- Use SIZE_MAX rather than (size_t)-1, to improve readability.
- Move the only branch that breaks to the first place, so that we
remove an else. This reduces nesting while parsing the code.
- Now that we only have a 2-branch conditional where both branches
assign to the same variable, rewrite it as a ternary, to shorten.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
break;
}
- if (length <= ((size_t)-1 / 4)) {
- length *= 4;
- } else if (length == (size_t) -1) {
+ if (length == SIZE_MAX) {
break;
- } else {
- length = (size_t) -1;
}
+
+ length = (length <= SIZE_MAX / 4) ? length * 4 : SIZE_MAX;
}
free(buffer);