From 0d9193dcf6e0d25e7b24759ed56398d918994348 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sat, 15 Nov 2025 22:02:33 +0100 Subject: [PATCH] lib/: Rename XMALLOC() => xmalloc_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 --- lib/alloc/malloc.h | 3 ++- lib/copydir.c | 2 +- lib/env.c | 2 +- lib/idmapping.c | 2 +- lib/list.c | 8 ++++---- lib/utmp.c | 6 +++--- src/gpasswd.c | 2 +- src/groupmems.c | 8 ++++---- src/groupmod.c | 10 +++++----- src/login.c | 2 +- src/su.c | 2 +- src/useradd.c | 2 +- src/usermod.c | 2 +- tests/unit/test_exit_if_null.c | 6 +++--- 14 files changed, 29 insertions(+), 28 deletions(-) diff --git a/lib/alloc/malloc.h b/lib/alloc/malloc.h index e269c6f2c..1e3a69291 100644 --- a/lib/alloc/malloc.h +++ b/lib/alloc/malloc.h @@ -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 diff --git a/lib/copydir.c b/lib/copydir.c index 3cf81fb54..27bc1a630 100644 --- a/lib/copydir.c +++ b/lib/copydir.c @@ -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; diff --git a/lib/env.c b/lib/env.c index 97339c648..f97bb1027 100644 --- 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; } diff --git a/lib/idmapping.c b/lib/idmapping.c index 5ae77b7d0..485195bad 100644 --- a/lib/idmapping.c +++ b/lib/idmapping.c @@ -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 */ diff --git a/lib/list.c b/lib/list.c index e411307d3..cf918f477 100644 --- a/lib/list.c +++ b/lib/list.c @@ -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 diff --git a/lib/utmp.c b/lib/utmp.c index 8ed9528f9..0bff45af1 100644 --- a/lib/utmp.c +++ b/lib/utmp.c @@ -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; } diff --git a/src/gpasswd.c b/src/gpasswd.c index 98cc53d05..0c364321d 100644 --- a/src/gpasswd.c +++ b/src/gpasswd.c @@ -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; } diff --git a/src/groupmems.c b/src/groupmems.c index 0da8086cc..d8fd42441 100644 --- a/src/groupmems.c +++ b/src/groupmems.c @@ -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 */ diff --git a/src/groupmod.c b/src/groupmod.c index ac5636d1d..22d07fe69 100644 --- a/src/groupmod.c +++ b/src/groupmod.c @@ -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; diff --git a/src/login.c b/src/login.c index 6798bb1d0..076dd3d4d 100644 --- a/src/login.c +++ b/src/login.c @@ -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, "")) { diff --git a/src/su.c b/src/su.c index 86f84304b..e9b3f0f7b 100644 --- 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); diff --git a/src/useradd.c b/src/useradd.c index bf7c8f7c3..c179ff4aa 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -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 */ diff --git a/src/usermod.c b/src/usermod.c index d391330b1..074b41fe2 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -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 (); diff --git a/tests/unit/test_exit_if_null.c b/tests/unit/test_exit_if_null.c index 392a7f47a..819239f50 100644 --- a/tests/unit/test_exit_if_null.c +++ b/tests/unit/test_exit_if_null.c @@ -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); } -- 2.47.3