]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Use calloc(3) instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Sat, 4 Feb 2023 20:43:43 +0000 (21:43 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 24 Feb 2023 02:28:43 +0000 (20:28 -0600)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/pwmem.c
lib/sgroupio.c
lib/shadowmem.c
libmisc/find_new_gid.c

index 867e3f74ebbf84520fac4df4a61d7ebb0a61c843..a25e19286dcf4ac6e998b1606d4b1de7fd7d6ed4 100644 (file)
 {
        struct passwd *pw;
 
-       pw = (struct passwd *) malloc (sizeof *pw);
+       pw = (struct passwd *) calloc (1, sizeof *pw);
        if (NULL == pw) {
                return NULL;
        }
        /* The libc might define other fields. They won't be copied. */
-       memset (pw, 0, sizeof *pw);
        pw->pw_uid = pwent->pw_uid;
        pw->pw_gid = pwent->pw_gid;
        /*@-mustfreeonly@*/
index b4d0589c142b58eddd785170f313395bc55d3e93..ab584c34b03980becad9a3a1ed15ab648945f966 100644 (file)
        struct sgrp *sg;
        int i;
 
-       sg = (struct sgrp *) malloc (sizeof *sg);
+       sg = (struct sgrp *) calloc (1, sizeof *sg);
        if (NULL == sg) {
                return NULL;
        }
        /* Do the same as the other _dup function, even if we know the
         * structure. */
-       memset (sg, 0, sizeof *sg);
        /*@-mustfreeonly@*/
        sg->sg_name = strdup (sgent->sg_name);
        /*@=mustfreeonly@*/
index 82f99e72c9dc290f62d20643f6d2ca4a4670ca15..9e46d0ceb4123dafb1c995aa286c99637656c640 100644 (file)
 {
        struct spwd *sp;
 
-       sp = (struct spwd *) malloc (sizeof *sp);
+       sp = (struct spwd *) calloc (1, sizeof *sp);
        if (NULL == sp) {
                return NULL;
        }
        /* The libc might define other fields. They won't be copied. */
-       memset (sp, 0, sizeof *sp);
        sp->sp_lstchg = spent->sp_lstchg;
        sp->sp_min    = spent->sp_min;
        sp->sp_max    = spent->sp_max;
index da1d8d553f74018674e503b7202c29148094731c..808cd7ce5f81bea45ef68a22f009c10ca9842456 100644 (file)
@@ -231,14 +231,13 @@ int find_new_gid (bool sys_group,
         */
 
        /* Create an array to hold all of the discovered GIDs */
-       used_gids = malloc (sizeof (bool) * (gid_max +1));
+       used_gids = calloc (gid_max + 1, sizeof (bool));
        if (NULL == used_gids) {
                fprintf (log_get_logfd(),
                         _("%s: failed to allocate memory: %s\n"),
                         log_get_progname(), strerror (errno));
                return -1;
        }
-       memset (used_gids, false, sizeof (bool) * (gid_max + 1));
 
        /* First look for the lowest and highest value in the local database */
        (void) gr_rewind ();