]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/: Rename XMALLOC() => xmalloc_T()
authorAlejandro Colomar <alx@kernel.org>
Sat, 15 Nov 2025 21:02:33 +0000 (22:02 +0100)
committerSerge Hallyn <serge@hallyn.com>
Sat, 6 Dec 2025 03:22:45 +0000 (21:22 -0600)
The 'T' in the name notes that this API is a type-safe variant of the
API it wraps.  This makes the names more explicative.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 files changed:
lib/alloc/malloc.h
lib/copydir.c
lib/env.c
lib/idmapping.c
lib/list.c
lib/utmp.c
src/gpasswd.c
src/groupmems.c
src/groupmod.c
src/login.c
src/su.c
src/useradd.c
src/usermod.c
tests/unit/test_exit_if_null.c

index e269c6f2c61711688d77f558201f9817238aa38c..1e3a69291a21076883442213ad31489a923f3c89 100644 (file)
@@ -23,7 +23,8 @@
 })
 
 
-#define XMALLOC(n, T)  exit_if_null(malloc_T(n, T))
+// xmalloc_T - exit-on-error malloc type-safe
+#define xmalloc_T(n, T)  exit_if_null(malloc_T(n, T))
 
 
 // mallocarray - malloc array
index 3cf81fb5461c5c2d8214adff5888c651b0626620..27bc1a630580664994b9ce6a036230e9874aa409 100644 (file)
@@ -229,7 +229,7 @@ static /*@exposed@*/ /*@null@*/struct link_name *check_link (const char *name, c
                return NULL;
        }
 
-       lp = XMALLOC(1, struct link_name);
+       lp = xmalloc_T(1, struct link_name);
        lp->ln_dev = sb->st_dev;
        lp->ln_ino = sb->st_ino;
        lp->ln_count = sb->st_nlink;
index 97339c64852bd2f4cd71c8662657336d16a68671..f97bb10272845a7e0c521ab979681ac67415ea02 100644 (file)
--- a/lib/env.c
+++ b/lib/env.c
@@ -68,7 +68,7 @@ static const char *const noslash[] = {
  */
 void initenv (void)
 {
-       newenvp = XMALLOC(NEWENVP_STEP, char *);
+       newenvp = xmalloc_T(NEWENVP_STEP, char *);
        *newenvp = NULL;
 }
 
index 5ae77b7d0d2ab2adea9da84d75b66c270dacf410..485195bad7a69d71c93ba492cf8295e9ba551ebc 100644 (file)
@@ -177,7 +177,7 @@ void write_mapping(int proc_dir_fd, int ranges, const struct map_range *mappings
 #endif
 
        bufsize = (ULONG_DIGITS + 1) * 3 * ranges + 1;
-       pos = buf = XMALLOC(bufsize, char);
+       pos = buf = xmalloc_T(bufsize, char);
        end = buf + bufsize;
 
        /* Build the mapping command */
index e411307d33b95442b51747f61ed9f3ab613a847c..cf918f477f1b117bdb9b4065453515685e5c1021 100644 (file)
@@ -53,7 +53,7 @@ add_list(/*@returned@*/ /*@only@*/char **list, const char *member)
         * old entries, and the new entries as well.
         */
 
-       tmp = XMALLOC(i + 2, char *);
+       tmp = xmalloc_T(i + 2, char *);
 
        /*
         * Copy the original list to the new list, then append the
@@ -108,7 +108,7 @@ del_list(/*@returned@*/ /*@only@*/char **list, const char *member)
         * old entries.
         */
 
-       tmp = XMALLOC(j + 1, char *);
+       tmp = xmalloc_T(j + 1, char *);
 
        /*
         * Copy the original list except the deleted members to the
@@ -144,7 +144,7 @@ dup_list(char *const *list)
 
        for (i = 0; NULL != list[i]; i++);
 
-       tmp = XMALLOC(i + 1, char *);
+       tmp = xmalloc_T(i + 1, char *);
 
        i = 0;
        while (NULL != *list) {
@@ -214,7 +214,7 @@ comma_to_list(const char *comma)
         */
 
        n = strchrcnt(members, ',') + 2;
-       array = XMALLOC(n, char *);
+       array = xmalloc_T(n, char *);
 
        /*
         * Empty list is special - 0 members, not 1 empty member.  --marekm
index 8ed9528f9ca7daea8d48b6f9a51258dc23d59f82..0bff45af1432ad83c6de63ef362f4b39c1edd17e 100644 (file)
@@ -167,14 +167,14 @@ get_current_utmp(pid_t main_pid)
                                break; /* Perfect match, stop the search */
 
                        if (NULL == ut_by_pid) {
-                               ut_by_pid = XMALLOC(1, struct utmpx);
+                               ut_by_pid = xmalloc_T(1, struct utmpx);
                                *ut_by_pid = *ut;
                        }
 
                } else if (   (NULL == ut_by_line)
                           && (LOGIN_PROCESS == ut->ut_type) /* Be more picky when matching by 'ut_line' only */
                           && (is_my_tty(ut->ut_line))) {
-                       ut_by_line = XMALLOC(1, struct utmpx);
+                       ut_by_line = xmalloc_T(1, struct utmpx);
                        *ut_by_line = *ut;
                }
        }
@@ -185,7 +185,7 @@ get_current_utmp(pid_t main_pid)
        if (NULL != ut) {
                struct utmpx  *ut_copy;
 
-               ut_copy = XMALLOC(1, struct utmpx);
+               ut_copy = xmalloc_T(1, struct utmpx);
                memcpy(ut_copy, ut, sizeof(*ut));
                ut = ut_copy;
        }
index 98cc53d056a7dbb5ba4e05a55636e5cedfb21137..0c364321d9380c91b377ae91ef92a3955d13ad03 100644 (file)
@@ -777,7 +777,7 @@ static void get_group(struct group *gr, const struct option_flags *flags)
 
                        sg->sg_mem = dup_list (gr->gr_mem);
 
-                       sg->sg_adm = XMALLOC(1, char *);
+                       sg->sg_adm = xmalloc_T(1, char *);
                        sg->sg_adm[0] = NULL;
 
                }
index 0da8086ccf8553828b51c0c5b75fa72c13de1e11..d8fd424418c424ff8d20f84bf83ab62ca4b429ca 100644 (file)
@@ -142,7 +142,7 @@ static void add_user (const char *user,
                        static struct sgrp sgrent;
                        sgrent.sg_namp = xstrdup (newgrp->gr_name);
                        sgrent.sg_mem = dup_list (newgrp->gr_mem);
-                       sgrent.sg_adm = XMALLOC(1, char *);
+                       sgrent.sg_adm = xmalloc_T(1, char *);
                        sgrent.sg_adm[0] = NULL;
 
                        /* Move any password to gshadow */
@@ -218,7 +218,7 @@ static void remove_user (const char *user,
                        static struct sgrp sgrent;
                        sgrent.sg_namp = xstrdup (newgrp->gr_name);
                        sgrent.sg_mem = dup_list (newgrp->gr_mem);
-                       sgrent.sg_adm = XMALLOC(1, char *);
+                       sgrent.sg_adm = xmalloc_T(1, char *);
                        sgrent.sg_adm[0] = NULL;
 
                        /* Move any password to gshadow */
@@ -283,9 +283,9 @@ static void purge_members (const struct group *grp, bool process_selinux)
                        /* Create a shadow group based on this group */
                        static struct sgrp sgrent;
                        sgrent.sg_namp = xstrdup (newgrp->gr_name);
-                       sgrent.sg_mem = XMALLOC(1, char *);
+                       sgrent.sg_mem = xmalloc_T(1, char *);
                        sgrent.sg_mem[0] = NULL;
-                       sgrent.sg_adm = XMALLOC(1, char *);
+                       sgrent.sg_adm = xmalloc_T(1, char *);
                        sgrent.sg_adm[0] = NULL;
 
                        /* Move any password to gshadow */
index ac5636d1dbf2c33ab3e7eaa09e41f23189e0d11c..22d07fe69beb63b5eae0185dda922709c8bd310a 100644 (file)
@@ -263,7 +263,7 @@ grp_update(void)
 
                if (!aflg) {
                        // requested to replace the existing groups
-                       grp.gr_mem = XMALLOC(1, char *);
+                       grp.gr_mem = xmalloc_T(1, char *);
                        grp.gr_mem[0] = NULL;
                } else {
                        // append to existing groups
@@ -273,7 +273,7 @@ grp_update(void)
 #ifdef SHADOWGRP
                if (NULL != osgrp) {
                        if (!aflg) {
-                               sgrp.sg_mem = XMALLOC(1, char *);
+                               sgrp.sg_mem = xmalloc_T(1, char *);
                                sgrp.sg_mem[0] = NULL;
                        } else {
                                if (NULL != sgrp.sg_mem[0])
@@ -593,15 +593,15 @@ static void prepare_failure_reports (void)
 #endif
        info_passwd.name  = group_name;
 
-       gr                     = XMALLOC(512, char);
+       gr                     = xmalloc_T(512, char);
        info_group.audit_msg   = gr;
        gr_end                 = gr + 512;
 #ifdef SHADOWGRP
-       sgr                    = XMALLOC(512, char);
+       sgr                    = xmalloc_T(512, char);
        info_gshadow.audit_msg = sgr;
        sgr_end                = sgr + 512;
 #endif
-       pw                     = XMALLOC(512, char);
+       pw                     = xmalloc_T(512, char);
        info_passwd.audit_msg  = pw;
        pw_end                 = pw + 512;
 
index 6798bb1d02939c317c27218593d559b23ecdc0d6..076dd3d4d087e5b56e1b1a20107dca6f75df84b9 100644 (file)
@@ -831,7 +831,7 @@ int main (int argc, char **argv)
                                exit (1);
                        }
                        preauth_flag = false;
-                       username = XMALLOC(max_size, char);
+                       username = xmalloc_T(max_size, char);
                        login_prompt(username, max_size);
 
                        if (streq(username, "")) {
index 86f84304bd55d4407ace5cdadc50c13b9c9f292e..e9b3f0f7bb415003019ec95994691e3e455460f5 100644 (file)
--- a/src/su.c
+++ b/src/su.c
@@ -251,7 +251,7 @@ static void execve_shell (const char *shellname,
                while (NULL != args[n_args]) {
                        n_args++;
                }
-               targs = XMALLOC(n_args + 3, char *);
+               targs = xmalloc_T(n_args + 3, char *);
                targs[0] = "sh";
                targs[1] = "-";
                targs[2] = xstrdup (shellname);
index bf7c8f7c377828db3506a37f7e2325774446bc3c..c179ff4aad3160d686aedcbb6036c1ba69ecb96c 100644 (file)
@@ -2463,7 +2463,7 @@ int main (int argc, char **argv)
 #endif
 
        sys_ngroups = sysconf (_SC_NGROUPS_MAX);
-       user_groups = XMALLOC(1 + sys_ngroups, char *);
+       user_groups = xmalloc_T(1 + sys_ngroups, char *);
        /*
         * Initialize the list to be empty
         */
index d391330b1be45694591948342fccf1fc7a5f3ac8..074b41fe20d3ca60571bb0baf3eb7512cc428ad7 100644 (file)
@@ -2153,7 +2153,7 @@ int main (int argc, char **argv)
 #endif
 
        sys_ngroups = sysconf (_SC_NGROUPS_MAX);
-       user_groups = XMALLOC(sys_ngroups + 1, char *);
+       user_groups = xmalloc_T(sys_ngroups + 1, char *);
        user_groups[0] = NULL;
 
        is_shadow_pwd = spw_file_present ();
index 392a7f47a9a464dd3d07ceaf58c9c8075903eb3f..819239f502aebbd2fa3680be20e37cb67e40b1d6 100644 (file)
@@ -61,7 +61,7 @@ test_exit_if_null_exit(void **)
        switch (setjmp(jmpb)) {
        case 0:
                p = "called";
-               p = XMALLOC(SIZE_MAX, char);
+               p = xmalloc_T(SIZE_MAX, char);
                assert_unreachable();
                break;
        case EXIT_CALLED:
@@ -84,13 +84,13 @@ test_exit_if_null_ok(void **)
 
        static const char  foo[] = "foo1bar";
 
-       p = XMALLOC(countof(foo), char);
+       p = xmalloc_T(countof(foo), char);
        assert_true(p != NULL);
        strcpy(p, foo);
        assert_string_equal(p, "foo1bar");
        free(p);
 
-       p = XMALLOC(0, char);
+       p = xmalloc_T(0, char);
        assert_true(p != NULL);
        free(p);
 }