]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/: Rename MALLOC() => malloc_T()
authorAlejandro Colomar <alx@kernel.org>
Sat, 15 Nov 2025 21:01:20 +0000 (22:01 +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>
17 files changed:
lib/agetpass.c
lib/alloc/malloc.h
lib/commonio.c
lib/fs/readlink/areadlink.h
lib/groupio.c
lib/groupmem.c
lib/nss.c
lib/sgroupio.c
lib/shadow/grp/agetgroups.h
lib/shadow/gshadow/putsgent.c
lib/sssd.c
lib/string/strtok/astrsep2ls.h
lib/subordinateio.c
lib/xgetXXbyYY.c
src/usermod.c
tests/libsubid/04_nss/libsubid_zzz.c
tests/unit/test_chkname.c

index ae735403546c6a9bdbf9dd1f101fb16d8d99619e..a0d5714959b5de6f6387c69b5ff55486b517b7d3 100644 (file)
@@ -106,7 +106,7 @@ agetpass_internal(const char *prompt, int flags)
         * Let's add one more byte, and if the password uses it, it
         * means the introduced password was longer than PASS_MAX.
         */
-       pass = MALLOC(PASS_MAX + 2, char);
+       pass = malloc_T(PASS_MAX + 2, char);
        if (pass == NULL)
                return NULL;
 
index d9ffc36271bb1179a26f14b358eaeecd9529f1bb..e269c6f2c61711688d77f558201f9817238aa38c 100644 (file)
 #include "sizeof.h"
 
 
-#define MALLOC(n, T)   MALLOC_(n, typeas(T))
-#define MALLOC_(n, T)                                                 \
+// malloc_T - malloc type-safe
+#define malloc_T(n, T)   malloc_T_(n, typeas(T))
+#define malloc_T_(n, T)                                               \
 ({                                                                    \
        (T *){mallocarray(n, sizeof(T))};                             \
 })
 
 
-#define XMALLOC(n, T)  exit_if_null(MALLOC(n, T))
+#define XMALLOC(n, T)  exit_if_null(malloc_T(n, T))
 
 
+// mallocarray - malloc array
 ATTR_ALLOC_SIZE(1, 2)
 ATTR_MALLOC(free)
 inline void *mallocarray(size_t nmemb, size_t size);
index 3115acd211f144f814e2c0247f599c809626ff40..2c6a1a20f00d6845647c8e663387030b28790aa0 100644 (file)
@@ -655,7 +655,7 @@ commonio_open(struct commonio_db *db, int mode)
                        }
                }
 
-               p = MALLOC(1, struct commonio_entry);
+               p = malloc_T(1, struct commonio_entry);
                if (NULL == p) {
                        goto cleanup_entry;
                }
@@ -731,7 +731,7 @@ commonio_sort (struct commonio_db *db, int (*cmp) (const void *, const void *))
                return 0;
        }
 
-       entries = MALLOC(n, struct commonio_entry *);
+       entries = malloc_T(n, struct commonio_entry *);
        if (entries == NULL) {
                return -1;
        }
@@ -1058,7 +1058,7 @@ int commonio_update (struct commonio_db *db, const void *eptr)
                return 1;
        }
        /* not found, new entry */
-       p = MALLOC(1, struct commonio_entry);
+       p = malloc_T(1, struct commonio_entry);
        if (NULL == p) {
                db->ops->cio_free(nentry);
                errno = ENOMEM;
@@ -1095,7 +1095,7 @@ int commonio_append (struct commonio_db *db, const void *eptr)
                return 0;
        }
        /* new entry */
-       p = MALLOC(1, struct commonio_entry);
+       p = malloc_T(1, struct commonio_entry);
        if (NULL == p) {
                db->ops->cio_free(nentry);
                errno = ENOMEM;
index ccab8a72b4b6d6be9362cdc95a03baae29b87872..2a35be75edb5e5f185c8fe6d019c0564687a7776 100644 (file)
@@ -33,7 +33,7 @@ areadlink(const char *link)
                int   len;
                char  *buf;
 
-               buf = MALLOC(size, char);
+               buf = malloc_T(size, char);
                if (NULL == buf)
                        return NULL;
 
index a28e96c599181162f8d16e81073b720c79accae9..e1d984de37b031e7728ce9421334031f7839a3ff 100644 (file)
@@ -405,7 +405,7 @@ static int split_groups (unsigned int max_members)
                        continue;
                }
 
-               new = MALLOC(1, struct commonio_entry);
+               new = malloc_T(1, struct commonio_entry);
                if (NULL == new) {
                        return 0;
                }
index fd78e171e5f8b6c6ec0624ead74f1b1ce52861e4..c1189f3cdb4674ded97f3d173c3da652a89c88b8 100644 (file)
@@ -49,7 +49,7 @@
        for (i = 0; grent->gr_mem[i]; i++);
 
        /*@-mustfreeonly@*/
-       gr->gr_mem = MALLOC(i + 1, char *);
+       gr->gr_mem = malloc_T(i + 1, char *);
        /*@=mustfreeonly@*/
        if (NULL == gr->gr_mem) {
                gr_free(gr);
index 21a149db06a1f2907f0786ab5bc404e285aa01fb..f2112d08b6dab2ee1caf994577cdb11cb3eaab04 100644 (file)
--- a/lib/nss.c
+++ b/lib/nss.c
@@ -116,7 +116,7 @@ nss_init(const char *nsswitch_path) {
                fprintf(shadow_logfd, "Using files\n");
                goto null_subid;
        }
-       subid_nss = MALLOC(1, struct subid_nss_ops);
+       subid_nss = malloc_T(1, struct subid_nss_ops);
        if (!subid_nss) {
                goto close_lib;
        }
index 5df3ffc71be8b60e15deec774fe63189c597510d..09e6fbba0bb2a2567cfe5617c02c3262be3b18c9 100644 (file)
@@ -58,7 +58,7 @@
 
        for (i = 0; NULL != sgent->sg_adm[i]; i++);
        /*@-mustfreeonly@*/
-       sg->sg_adm = MALLOC(i + 1, char *);
+       sg->sg_adm = malloc_T(i + 1, char *);
        /*@=mustfreeonly@*/
        if (NULL == sg->sg_adm) {
                free (sg->sg_passwd);
@@ -83,7 +83,7 @@
 
        for (i = 0; NULL != sgent->sg_mem[i]; i++);
        /*@-mustfreeonly@*/
-       sg->sg_mem = MALLOC(i + 1, char *);
+       sg->sg_mem = malloc_T(i + 1, char *);
        /*@=mustfreeonly@*/
        if (NULL == sg->sg_mem) {
                for (i = 0; NULL != sg->sg_adm[i]; i++) {
index a1014dd76c85d28f807652300bd84c2bf1571aee..8c1c2f95eee4e2a3fa7b08f4b3ba9e5ec270aefd 100644 (file)
@@ -36,7 +36,7 @@ agetgroups(size_t *ngids)
 
        n = n ?: 1;
 
-       gids = MALLOC(n, gid_t);
+       gids = malloc_T(n, gid_t);
        if (gids == NULL)
                return NULL;
 
index 488f4a0e4b6a7509eae10516c74ac6947e6bdb65..7a7b98727fce39b2489805a608e0ddf3d975a8fb 100644 (file)
@@ -49,7 +49,7 @@ putsgent(const struct sgrp *sgrp, FILE *fp)
                size += strlen (sgrp->sg_mem[i]) + 1;
        }
 
-       buf = MALLOC(size, char);
+       buf = malloc_T(size, char);
        if (NULL == buf) {
                return -1;
        }
index 7b6dba41a99c46ae8cebcd65b81d52c5e3af2ea6..b915b80a6c48df5b05ec0469001d44d3da18f0c0 100644 (file)
@@ -40,7 +40,7 @@ sssd_flush_cache(int dbflags)
        if (rv == -1 && errno == ENOENT)
                return 0;
 
-       sss_cache_args = MALLOC(4, char);
+       sss_cache_args = malloc_T(4, char);
        if (sss_cache_args == NULL) {
            return -1;
        }
index 1a58e1c590bda556350534d24af3a51efb58607c..aa9283a119d703586d35496c79d3dcd608a0aca5 100644 (file)
@@ -36,7 +36,7 @@ astrsep2ls(char *s, const char *restrict delim, size_t *restrict np)
 
        n = strchrscnt(s, delim) + 2;
 
-       ls = MALLOC(n, char *);
+       ls = malloc_T(n, char *);
        if (ls == NULL)
                return NULL;
 
index 978e4c6ce05378bdcb451a5990c0780d08c5f7a2..b038379ef316c11df65476bc30a21b5deebccc18 100644 (file)
@@ -43,7 +43,7 @@ static /*@null@*/ /*@only@*/void *subordinate_dup (const void *ent)
        const struct subordinate_range *rangeent = ent;
        struct subordinate_range *range;
 
-       range = MALLOC(1, struct subordinate_range);
+       range = malloc_T(1, struct subordinate_range);
        if (NULL == range) {
                return NULL;
        }
index 8b7fc543aefd97e1e20215233427fe858e3c7443..2c9dbda58d28960cf71358df429a26ea1b972875 100644 (file)
@@ -53,7 +53,7 @@
        /* we have to start with something */
        size_t length = 0x100;
 
-       result = MALLOC(1, LOOKUP_TYPE);
+       result = malloc_T(1, LOOKUP_TYPE);
        if (NULL == result) {
                goto oom;
        }
index b8a8815caf18d93cdf2511589c7b9a8fe9e003f0..d391330b1be45694591948342fccf1fc7a5f3ac8 100644 (file)
@@ -366,7 +366,7 @@ prepend_range(const char *str, struct id_range_list_entry **head)
        if (range.first > range.last)
                return 0;
 
-       entry = MALLOC(1, struct id_range_list_entry);
+       entry = malloc_T(1, struct id_range_list_entry);
        if (!entry) {
                fprintf (stderr,
                        _("%s: failed to allocate memory: %s\n"),
index d8141ba3b1ee3bdcf5f9ad4ff31b73f886c7c83e..2e929687ec39bff2f803e9f68adc1b171782dddc 100644 (file)
@@ -77,7 +77,7 @@ static uid_t getnamuid(const char *name) {
 }
 
 static int alloc_uid(uid_t **uids, uid_t id) {
-       *uids = MALLOC(1, uid_t);
+       *uids = malloc_T(1, uid_t);
        if (!*uids)
                return -1;
        *uids[0] = id;
@@ -122,7 +122,7 @@ enum subid_status shadow_subid_list_owner_ranges(const char *owner, enum subid_t
                return SUBID_STATUS_SUCCESS;
        if (id_type == ID_TYPE_UID && strcmp(owner, "group1") == 0)
                return SUBID_STATUS_SUCCESS;
-       ranges = MALLOC(1, struct subid_range);
+       ranges = malloc_T(1, struct subid_range);
        if (!ranges)
                return SUBID_STATUS_ERROR;
        if (strcmp(owner, "user1") == 0 || strcmp(owner, "group1") == 0) {
index e22781207d29760bbc928197f851484cd58b2014..dfb04c9204dddfbdd93f99e66f6d628720651418 100644 (file)
@@ -134,7 +134,7 @@ test_is_valid_user_name_long(void **)
        char    *name;
 
        max = sysconf(_SC_LOGIN_NAME_MAX);
-       name = MALLOC(max + 1, char);
+       name = malloc_T(max + 1, char);
        assert_true(name != NULL);
 
        memset(name, '_', max);