]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
xgetXXbyYY: Simplify elifs
authorAlejandro Colomar <alx@kernel.org>
Sat, 27 May 2023 01:26:52 +0000 (03:26 +0200)
committerSerge Hallyn <serge@hallyn.com>
Tue, 30 May 2023 18:56:55 +0000 (13:56 -0500)
-  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>
libmisc/xgetXXbyYY.c

index 36b9a150d3a5a97c63270a9cc97f9f7bdfbf737b..c0782ff40664262c8690d3ebfb2a78d5f7a4c9da 100644 (file)
                        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);