From d9f0246611aea527f21c15256a6340c618f22d73 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sat, 27 May 2023 03:26:52 +0200 Subject: [PATCH] xgetXXbyYY: Simplify elifs - 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 --- libmisc/xgetXXbyYY.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libmisc/xgetXXbyYY.c b/libmisc/xgetXXbyYY.c index 36b9a150d..c0782ff40 100644 --- a/libmisc/xgetXXbyYY.c +++ b/libmisc/xgetXXbyYY.c @@ -79,13 +79,11 @@ 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); -- 2.47.2