From: Alejandro Colomar Date: Sat, 15 Nov 2025 21:01:20 +0000 (+0100) Subject: lib/: Rename MALLOC() => malloc_T() X-Git-Tag: 4.19.0-rc1~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0afe2169537de5459f5129d2f7af68f675c6b27a;p=thirdparty%2Fshadow.git lib/: Rename MALLOC() => malloc_T() 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 --- diff --git a/lib/agetpass.c b/lib/agetpass.c index ae7354035..a0d571495 100644 --- a/lib/agetpass.c +++ b/lib/agetpass.c @@ -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; diff --git a/lib/alloc/malloc.h b/lib/alloc/malloc.h index d9ffc3627..e269c6f2c 100644 --- a/lib/alloc/malloc.h +++ b/lib/alloc/malloc.h @@ -15,16 +15,18 @@ #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); diff --git a/lib/commonio.c b/lib/commonio.c index 3115acd21..2c6a1a20f 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -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; diff --git a/lib/fs/readlink/areadlink.h b/lib/fs/readlink/areadlink.h index ccab8a72b..2a35be75e 100644 --- a/lib/fs/readlink/areadlink.h +++ b/lib/fs/readlink/areadlink.h @@ -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; diff --git a/lib/groupio.c b/lib/groupio.c index a28e96c59..e1d984de3 100644 --- a/lib/groupio.c +++ b/lib/groupio.c @@ -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; } diff --git a/lib/groupmem.c b/lib/groupmem.c index fd78e171e..c1189f3cd 100644 --- a/lib/groupmem.c +++ b/lib/groupmem.c @@ -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); diff --git a/lib/nss.c b/lib/nss.c index 21a149db0..f2112d08b 100644 --- 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; } diff --git a/lib/sgroupio.c b/lib/sgroupio.c index 5df3ffc71..09e6fbba0 100644 --- a/lib/sgroupio.c +++ b/lib/sgroupio.c @@ -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++) { diff --git a/lib/shadow/grp/agetgroups.h b/lib/shadow/grp/agetgroups.h index a1014dd76..8c1c2f95e 100644 --- a/lib/shadow/grp/agetgroups.h +++ b/lib/shadow/grp/agetgroups.h @@ -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; diff --git a/lib/shadow/gshadow/putsgent.c b/lib/shadow/gshadow/putsgent.c index 488f4a0e4..7a7b98727 100644 --- a/lib/shadow/gshadow/putsgent.c +++ b/lib/shadow/gshadow/putsgent.c @@ -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; } diff --git a/lib/sssd.c b/lib/sssd.c index 7b6dba41a..b915b80a6 100644 --- a/lib/sssd.c +++ b/lib/sssd.c @@ -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; } diff --git a/lib/string/strtok/astrsep2ls.h b/lib/string/strtok/astrsep2ls.h index 1a58e1c59..aa9283a11 100644 --- a/lib/string/strtok/astrsep2ls.h +++ b/lib/string/strtok/astrsep2ls.h @@ -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; diff --git a/lib/subordinateio.c b/lib/subordinateio.c index 978e4c6ce..b038379ef 100644 --- a/lib/subordinateio.c +++ b/lib/subordinateio.c @@ -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; } diff --git a/lib/xgetXXbyYY.c b/lib/xgetXXbyYY.c index 8b7fc543a..2c9dbda58 100644 --- a/lib/xgetXXbyYY.c +++ b/lib/xgetXXbyYY.c @@ -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; } diff --git a/src/usermod.c b/src/usermod.c index b8a8815ca..d391330b1 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -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"), diff --git a/tests/libsubid/04_nss/libsubid_zzz.c b/tests/libsubid/04_nss/libsubid_zzz.c index d8141ba3b..2e929687e 100644 --- a/tests/libsubid/04_nss/libsubid_zzz.c +++ b/tests/libsubid/04_nss/libsubid_zzz.c @@ -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) { diff --git a/tests/unit/test_chkname.c b/tests/unit/test_chkname.c index e22781207..dfb04c920 100644 --- a/tests/unit/test_chkname.c +++ b/tests/unit/test_chkname.c @@ -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);