]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/chkname.c: Use tmp variable to avoid a -Wsign-compare warning
authorAlejandro Colomar <alx@kernel.org>
Sat, 2 Sep 2023 12:15:43 +0000 (14:15 +0200)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Mon, 4 Dec 2023 10:45:09 +0000 (11:45 +0100)
I used size_t because:

sysconf(3) can return -1 if the value is not supported, but then it can
only mean that there's no limit.  Having no limit is the same as having
a limit of SIZE_MAX (to which -1 is converted).

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/chkname.c

index 0a18af2bf8a8d29dd8503f0118c6b3b116163c92..cbfbff51a04a7cf2c5ec8409ba7f1fb59013ca8f 100644 (file)
@@ -74,12 +74,14 @@ static bool is_valid_name (const char *name)
 
 bool is_valid_user_name (const char *name)
 {
+       size_t  maxlen;
+
        /*
         * User names length are limited by the kernel
         */
-       if (strlen (name) > sysconf(_SC_LOGIN_NAME_MAX)) {
+       maxlen = sysconf(_SC_LOGIN_NAME_MAX);
+       if (strlen(name) > maxlen)
                return false;
-       }
 
        return is_valid_name (name);
 }