]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: Use NULL instead of 0 as a null pointer constant
authorAlejandro Colomar <alx@kernel.org>
Wed, 13 Nov 2024 12:23:35 +0000 (13:23 +0100)
committerSerge Hallyn <serge@hallyn.com>
Wed, 13 Nov 2024 15:44:54 +0000 (09:44 -0600)
GCC 15 will add -Wzero-as-null-pointer-constant for deprecating it,
and I'm working on a paper for deprecating it from ISO C too.
Let's remove any uses in our code base.

I've done this change by building GCC from master, adding
-Werror=zero-as-null-pointer-constant to ./autogen.sh, and fixing every
error that showed up.

Closes: <https://github.com/shadow-maint/shadow/issues/1120>
Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117059>
Link: <https://software.codidact.com/posts/292718/292759#answer-292759>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/commonio.c
lib/fputsx.c
lib/port.c
lib/run_part.c
lib/sgetpwent.c
src/grpconv.c
src/login_nopam.c
src/vipw.c

index 5e4dc92d0f714f3059ba72b08c2fef9b7f0f51c4..edf12866f2592f3e31c620e2dec837fc2fafb374 100644 (file)
@@ -1240,7 +1240,7 @@ int commonio_rewind (struct commonio_db *db)
 
        if (!db->isopen) {
                errno = EINVAL;
-               return 0;
+               return NULL;
        }
        if (NULL == db->cursor) {
                db->cursor = db->head;
index 72d62099232349c441b09c8c056631a73d6b17c1..a43c2ac139e8cf0a29300d591e169d81647935fb 100644 (file)
@@ -27,7 +27,7 @@ fgetsx(/*@returned@*/char *restrict buf, int cnt, FILE *restrict f)
        while (cnt > 0) {
                if (fgets (cp, cnt, f) != cp) {
                        if (cp == buf) {
-                               return 0;
+                               return NULL;
                        } else {
                                break;
                        }
index fe25fa9aface71b73b7caace4b9d428193676dfe..f56923e0000ae5358888d9dbe0696b5d21f6ca26 100644 (file)
@@ -121,7 +121,7 @@ getportent(void)
 
        if (NULL == ports) {
                errno = saveerr;
-               return 0;
+               return NULL;
        }
 
        /*
@@ -204,7 +204,7 @@ next:
        cp = field;
 
        if ('\0' == *cp) {
-               port.pt_times = 0;
+               port.pt_times = NULL;
                return &port;
        }
 
@@ -259,7 +259,7 @@ next:
                                break;
                        default:
                                errno = EINVAL;
-                               return 0;
+                               return NULL;
                        }
                }
 
@@ -380,7 +380,7 @@ bool isttytime (const char *id, const char *port, time_t when)
         * ever let them login.
         */
 
-       if (0 == pp->pt_times) {
+       if (NULL == pp->pt_times) {
                return false;
        }
 
index b271f4ce8a2582b2c4e9d824f29b4929e5fa2470..840d951197b7625f0ce1ac9088981f559d998bbe 100644 (file)
@@ -51,7 +51,7 @@ int run_parts(const char *directory, const char *name, const char *action)
        int n;
        int execute_result = 0;
 
-       scanlist = scandir(directory, &namelist, 0, alphasort);
+       scanlist = scandir(directory, &namelist, NULL, alphasort);
        if (scanlist<=0) {
                return (0);
        }
index 20136695d1092e9358dc22ae1bcf1abf69b8a1b6..5704d19aeb51066902b0fb94e7a5eae89d9e4c5c 100644 (file)
@@ -54,7 +54,7 @@ sgetpwent(const char *buf)
                fprintf (shadow_logfd,
                         "%s: Too long passwd entry encountered, file corruption?\n",
                         shadow_progname);
-               return 0;       /* fail if too long */
+               return NULL;    /* fail if too long */
        }
        strcpy (pwdbuf, buf);
 
index 4d941cdce10fa27f6db0740ae33f9c6b93193c76..ea236e4ed3cdc172041c8cbb2db13a942dadb807 100644 (file)
@@ -197,7 +197,7 @@ int main (int argc, char **argv)
                        if (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0)
                                sgent.sg_passwd = gr->gr_passwd;
                } else {
-                       static char *empty = 0;
+                       static char *empty = NULL;
 
                        /* add new shadow group entry */
                        bzero(&sgent, sizeof sgent);
index 2d979323e116217720376313590cb4b323c3016d..90f4b7315493bddc64849d709f1bac3cca9d1563 100644 (file)
@@ -166,7 +166,7 @@ static bool list_match (char *list, const char *item, bool (*match_fn) (const ch
                while (   ((tok = strtok (NULL, sep)) != NULL)
                       && (strcasecmp (tok, "EXCEPT") != 0))
                        /* VOID */ ;
-               if (tok == 0 || !list_match (NULL, item, match_fn)) {
+               if (tok == NULL || !list_match(NULL, item, match_fn)) {
                        return (match);
                }
        }
index 31c3b7795f3e01e3f456c13e2295926df7ada433..4df05b6f594ac4f1c84a2bea6af846353f593caf 100644 (file)
@@ -389,7 +389,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void))
                vipwexit (fileedit, 1, 1);
        }
        if (st1.st_mtime == st2.st_mtime) {
-               vipwexit (0, 0, 0);
+               vipwexit(NULL, 0, 0);
        }
 #ifdef WITH_SELINUX
        /* unset the fscreatecon */
@@ -446,7 +446,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void))
                        free(to_rename);
                }
 #endif                         /* WITH_TCB */
-               vipwexit (0, 0, 1);
+               vipwexit(NULL, 0, 1);
        }
 
 #ifdef WITH_TCB