CID #139583: plen + 1 is evaluated as int, and could in principle overflow.
So cast to ssize_t and add an additional check that our overflow calculation
doesn't overflow itself.
lines = DIV_ROUND_UP(len, width);
slen = strlen_ptr(sep);
- if (lines > (SSIZE_MAX - plen - 1 - slen) / (indent + width + 1))
+ if (plen >= SSIZE_MAX - 1 - slen ||
+ lines > (SSIZE_MAX - plen - 1 - slen) / (indent + width + 1))
return -ENOMEM;
- t = realloc(*prefix, plen + 1 + slen + (indent + width + 1) * lines);
+ t = realloc(*prefix, (ssize_t) plen + 1 + slen + (indent + width + 1) * lines);
if (!t)
return -ENOMEM;