From 34f7d3c8046d5756fd99d86f899c3b6b34ec7ae1 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Wed, 1 Jan 2025 14:41:18 +0100 Subject: [PATCH] lib/, src/: Use xaprintf() instead of xasprintf() This makes some temporary variables unnecessary. They'll be removed in the next commit. Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 4 ++-- lib/copydir.c | 6 +++--- lib/env.c | 4 ++-- lib/getdef.c | 6 +++--- lib/mail.c | 4 ++-- lib/obscure.c | 4 ++-- lib/prefix_flag.c | 16 ++++++++-------- lib/setupenv.c | 4 ++-- src/passwd.c | 4 ++-- src/su.c | 4 ++-- src/useradd.c | 14 +++++++------- src/userdel.c | 8 ++++---- src/usermod.c | 20 ++++++++++---------- src/vipw.c | 4 ++-- 14 files changed, 51 insertions(+), 51 deletions(-) diff --git a/lib/Makefile.am b/lib/Makefile.am index 4174482707..19bfd23185 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -184,8 +184,8 @@ libshadow_la_SOURCES = \ string/sprintf/snprintf.h \ string/sprintf/stpeprintf.c \ string/sprintf/stpeprintf.h \ - string/sprintf/xasprintf.c \ - string/sprintf/xasprintf.h \ + string/sprintf/xaprintf.c \ + string/sprintf/xaprintf.h \ string/strchr/strchrcnt.c \ string/strchr/strchrcnt.h \ string/strchr/stpspn.c \ diff --git a/lib/copydir.c b/lib/copydir.c index 05d3b7e449..5c4acc78e3 100644 --- a/lib/copydir.c +++ b/lib/copydir.c @@ -39,7 +39,7 @@ #endif /* WITH_ATTR */ #include "shadowlog.h" #include "string/sprintf/aprintf.h" -#include "string/sprintf/xasprintf.h" +#include "string/sprintf/xaprintf.h" #include "string/strcmp/streq.h" @@ -233,7 +233,7 @@ static /*@exposed@*/ /*@null@*/struct link_name *check_link (const char *name, c lp->ln_dev = sb->st_dev; lp->ln_ino = sb->st_ino; lp->ln_count = sb->st_nlink; - xasprintf(&lp->ln_name, "%s%s", dst_orig, name + strlen(src_orig)); + lp->ln_name = xaprintf("%s%s", dst_orig, name + strlen(src_orig)); lp->ln_next = links; links = lp; @@ -580,7 +580,7 @@ static int copy_symlink (const struct path_info *src, const struct path_info *ds if (strncmp(oldlink, src_orig, strlen(src_orig)) == 0) { char *dummy; - xasprintf(&dummy, "%s%s", dst_orig, oldlink + strlen(src_orig)); + dummy = xaprintf("%s%s", dst_orig, oldlink + strlen(src_orig)); free(oldlink); oldlink = dummy; } diff --git a/lib/env.c b/lib/env.c index 9cb3137122..7d9a4a512a 100644 --- a/lib/env.c +++ b/lib/env.c @@ -22,7 +22,7 @@ #include "defines.h" #include "shadowlog.h" #include "string/sprintf/snprintf.h" -#include "string/sprintf/xasprintf.h" +#include "string/sprintf/xaprintf.h" #include "string/strdup/xstrdup.h" @@ -77,7 +77,7 @@ void addenv (const char *string, /*@null@*/const char *value) size_t i, n; if (NULL != value) { - xasprintf(&newstring, "%s=%s", string, value); + newstring = xaprintf("%s=%s", string, value); } else { newstring = xstrdup (string); } diff --git a/lib/getdef.c b/lib/getdef.c index d234fe18b0..383cf3f4a5 100644 --- a/lib/getdef.c +++ b/lib/getdef.c @@ -29,7 +29,7 @@ #include "getdef.h" #include "prototypes.h" #include "shadowlog_internal.h" -#include "string/sprintf/xasprintf.h" +#include "string/sprintf/xaprintf.h" #include "string/strchr/stpspn.h" #include "string/strchr/strrspn.h" #include "string/strcmp/streq.h" @@ -455,10 +455,10 @@ void setdef_config_file (const char* file) #ifdef USE_ECONF char *cp; - xasprintf(&cp, "%s/%s", file, sysconfdir); + cp = xaprintf("%s/%s", file, sysconfdir); sysconfdir = cp; #ifdef VENDORDIR - xasprintf(&cp, "%s/%s", file, vendordir); + cp = xaprintf("%s/%s", file, vendordir); vendordir = cp; #endif #else diff --git a/lib/mail.c b/lib/mail.c index b62287e6a5..968bfa41ca 100644 --- a/lib/mail.c +++ b/lib/mail.c @@ -16,7 +16,7 @@ #include #include "getdef.h" -#include "string/sprintf/xasprintf.h" +#include "string/sprintf/xaprintf.h" #ident "$Id$" @@ -37,7 +37,7 @@ void mailcheck (void) if (NULL != mailbox) { char *newmail; - xasprintf(&newmail, "%s/new", mailbox); + newmail = xaprintf("%s/new", mailbox); if (stat (newmail, &statbuf) != -1 && statbuf.st_size != 0) { if (statbuf.st_mtime > statbuf.st_atime) { diff --git a/lib/obscure.c b/lib/obscure.c index d508200f4d..b8022bc6f5 100644 --- a/lib/obscure.c +++ b/lib/obscure.c @@ -20,7 +20,7 @@ #include "defines.h" #include "getdef.h" #include "string/memset/memzero.h" -#include "string/sprintf/xasprintf.h" +#include "string/sprintf/xaprintf.h" #include "string/strcmp/streq.h" #include "string/strdup/xstrdup.h" @@ -102,7 +102,7 @@ static /*@observer@*//*@null@*/const char *password_check ( newmono = str_lower (xstrdup (new)); oldmono = str_lower (xstrdup (old)); - xasprintf(&wrapped, "%s%s", oldmono, oldmono); + wrapped = xaprintf("%s%s", oldmono, oldmono); if (palindrome (oldmono, newmono)) { msg = _("a palindrome"); diff --git a/lib/prefix_flag.c b/lib/prefix_flag.c index c09b8d0826..4ac929122c 100644 --- a/lib/prefix_flag.c +++ b/lib/prefix_flag.c @@ -28,7 +28,7 @@ #endif /* ENABLE_SUBIDS */ #include "getdef.h" #include "shadowlog.h" -#include "string/sprintf/xasprintf.h" +#include "string/sprintf/xaprintf.h" #include "string/strcmp/streq.h" @@ -109,32 +109,32 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char ** exit (E_BAD_ARG); } - xasprintf(&passwd_db_file, "%s/%s", prefix, PASSWD_FILE); + passwd_db_file = xaprintf("%s/%s", prefix, PASSWD_FILE); pw_setdbname(passwd_db_file); - xasprintf(&group_db_file, "%s/%s", prefix, GROUP_FILE); + group_db_file = xaprintf("%s/%s", prefix, GROUP_FILE); gr_setdbname(group_db_file); #ifdef SHADOWGRP - xasprintf(&sgroup_db_file, "%s/%s", prefix, SGROUP_FILE); + sgroup_db_file = xaprintf("%s/%s", prefix, SGROUP_FILE); sgr_setdbname(sgroup_db_file); #endif - xasprintf(&spw_db_file, "%s/%s", prefix, SHADOW_FILE); + spw_db_file = xaprintf("%s/%s", prefix, SHADOW_FILE); spw_setdbname(spw_db_file); #ifdef ENABLE_SUBIDS - xasprintf(&suid_db_file, "%s/%s", prefix, SUBUID_FILE); + suid_db_file = xaprintf("%s/%s", prefix, SUBUID_FILE); sub_uid_setdbname(suid_db_file); - xasprintf(&sgid_db_file, "%s/%s", prefix, SUBGID_FILE); + sgid_db_file = xaprintf("%s/%s", prefix, SUBGID_FILE); sub_gid_setdbname(sgid_db_file); #endif #ifdef USE_ECONF setdef_config_file(prefix); #else - xasprintf(&def_conf_file, "%s/%s", prefix, "/etc/login.defs"); + def_conf_file = xaprintf("%s/%s", prefix, "/etc/login.defs"); setdef_config_file(def_conf_file); #endif } diff --git a/lib/setupenv.c b/lib/setupenv.c index 63f7fb95d1..7a891019a9 100644 --- a/lib/setupenv.c +++ b/lib/setupenv.c @@ -26,7 +26,7 @@ #include #include "getdef.h" #include "shadowlog.h" -#include "string/sprintf/xasprintf.h" +#include "string/sprintf/xaprintf.h" #include "string/strchr/stpspn.h" #include "string/strcmp/streq.h" #include "string/strdup/xstrdup.h" @@ -39,7 +39,7 @@ addenv_path(const char *varname, const char *dirname, const char *filename) { char *buf; - xasprintf(&buf, "%s/%s", dirname, filename); + buf = xaprintf("%s/%s", dirname, filename); addenv(varname, buf); free(buf); } diff --git a/src/passwd.c b/src/passwd.c index cc79960a54..86510319c0 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -33,7 +33,7 @@ #include "shadowlog.h" #include "sssd.h" #include "string/memset/memzero.h" -#include "string/sprintf/xasprintf.h" +#include "string/sprintf/xaprintf.h" #include "string/strcmp/streq.h" #include "string/strcpy/strtcpy.h" #include "string/strdup/xstrdup.h" @@ -534,7 +534,7 @@ static char *update_crypt_pw (char *cp) if (lflg && *cp != '!') { char *newpw; - xasprintf(&newpw, "!%s", cp); + newpw = xaprintf("!%s", cp); if (!use_pam) { if (do_update_pwd) { diff --git a/src/su.c b/src/su.c index 7b3c9b04ac..c9b7494f82 100644 --- a/src/su.c +++ b/src/su.c @@ -60,7 +60,7 @@ #include "prototypes.h" #include "shadowlog.h" #include "string/sprintf/snprintf.h" -#include "string/sprintf/xasprintf.h" +#include "string/sprintf/xaprintf.h" #include "string/strcmp/streq.h" #include "string/strcpy/strtcpy.h" #include "string/strdup/xstrdup.h" @@ -1211,7 +1211,7 @@ int main (int argc, char **argv) cp = Basename (shellstr); } - xasprintf(&arg0, "-%s", cp); + arg0 = xaprintf("-%s", cp); cp = arg0; } else { cp = Basename (shellstr); diff --git a/src/useradd.c b/src/useradd.c index 771d050b68..3adf2e1f13 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -67,7 +67,7 @@ #include "string/memset/memzero.h" #include "string/sprintf/aprintf.h" #include "string/sprintf/snprintf.h" -#include "string/sprintf/xasprintf.h" +#include "string/sprintf/xaprintf.h" #include "string/strcmp/streq.h" #include "string/strdup/xstrdup.h" #include "string/strtok/stpsep.h" @@ -447,7 +447,7 @@ get_defaults(void) if (prefix[0]) { char *dt; - xasprintf(&dt, "%s/%s", prefix, ccp); + dt = xaprintf("%s/%s", prefix, ccp); def_template = dt; } else { def_template = xstrdup(ccp); @@ -464,7 +464,7 @@ get_defaults(void) if (prefix[0]) { char *dut; - xasprintf(&dut, "%s/%s", prefix, ccp); + dut = xaprintf("%s/%s", prefix, ccp); def_usrtemplate = dut; } else { def_usrtemplate = xstrdup(ccp); @@ -1556,13 +1556,13 @@ static void process_flags (int argc, char **argv) if (!dflg) { char *uh; - xasprintf(&uh, "%s/%s", def_home, user_name); + uh = xaprintf("%s/%s", def_home, user_name); user_home = uh; } if (prefix[0]) { char *puh; /* to avoid const warning */ - xasprintf(&puh, "%s/%s", prefix, user_home); + puh = xaprintf("%s/%s", prefix, user_home); prefix_user_home = puh; } else { prefix_user_home = user_home; @@ -2375,9 +2375,9 @@ static void create_mail (void) return; } if (prefix[0]) - xasprintf(&file, "%s/%s/%s", prefix, spool, user_name); + file = xaprintf("%s/%s/%s", prefix, spool, user_name); else - xasprintf(&file, "%s/%s", spool, user_name); + file = xaprintf("%s/%s", spool, user_name); #ifdef WITH_SELINUX if (set_selinux_file_context(file, S_IFREG) != 0) { diff --git a/src/userdel.c b/src/userdel.c index 79cd4bd237..43ed391b45 100644 --- a/src/userdel.c +++ b/src/userdel.c @@ -52,7 +52,7 @@ #endif /* ENABLE_SUBIDS */ #include "shadowlog.h" #include "string/sprintf/aprintf.h" -#include "string/sprintf/xasprintf.h" +#include "string/sprintf/xaprintf.h" #include "string/strcmp/streq.h" #include "string/strdup/xstrdup.h" @@ -807,9 +807,9 @@ static int remove_mailbox (void) } if (prefix[0]) { - xasprintf(&mailfile, "%s/%s/%s", prefix, maildir, user_name); + mailfile = xaprintf("%s/%s/%s", prefix, maildir, user_name); } else { - xasprintf(&mailfile, "%s/%s", maildir, user_name); + mailfile = xaprintf("%s/%s", maildir, user_name); } if (access (mailfile, F_OK) != 0) { @@ -1117,7 +1117,7 @@ int main (int argc, char **argv) user_gid = pwd->pw_gid; if (prefix[0]) { - xasprintf(&user_home, "%s/%s", prefix, pwd->pw_dir); + user_home = xaprintf("%s/%s", prefix, pwd->pw_dir); } else { user_home = xstrdup(pwd->pw_dir); } diff --git a/src/usermod.c b/src/usermod.c index 24c5a4d23c..fba1c4af9d 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -63,7 +63,7 @@ #include "shadowlog.h" #include "sssd.h" #include "string/memset/memzero.h" -#include "string/sprintf/xasprintf.h" +#include "string/sprintf/xaprintf.h" #include "string/strcmp/streq.h" #include "string/strdup/xstrdup.h" #include "time/day_to_str.h" @@ -434,7 +434,7 @@ static char *new_pw_passwd (char *pw_pass) "updating passwd", user_newname, user_newid, 0); #endif SYSLOG ((LOG_INFO, "lock user '%s' password", user_newname)); - xasprintf(&buf, "!%s", pw_pass); + buf = xaprintf("!%s", pw_pass); pw_pass = buf; } else if (Uflg && pw_pass[0] == '!') { if (pw_pass[1] == '\0') { @@ -1291,10 +1291,10 @@ process_flags(int argc, char **argv) user_newgid = user_gid; } if (prefix[0]) { - xasprintf(&prefix_user_home, "%s/%s", prefix, user_home); + prefix_user_home = xaprintf("%s/%s", prefix, user_home); if (user_newhome) { - xasprintf(&prefix_user_newhome, "%s/%s", - prefix, user_newhome); + prefix_user_newhome = xaprintf("%s/%s", + prefix, user_newhome); } } else { prefix_user_home = user_home; @@ -2068,9 +2068,9 @@ static void move_mailbox (void) * between stat and chown). --marekm */ if (prefix[0]) { - xasprintf(&mailfile, "%s/%s/%s", prefix, maildir, user_name); + mailfile = xaprintf("%s/%s/%s", prefix, maildir, user_name); } else { - xasprintf(&mailfile, "%s/%s", maildir, user_name); + mailfile = xaprintf("%s/%s", maildir, user_name); } fd = open (mailfile, O_RDONLY | O_NONBLOCK, 0); @@ -2115,10 +2115,10 @@ static void move_mailbox (void) char *newmailfile; if (prefix[0]) { - xasprintf(&newmailfile, "%s/%s/%s", - prefix, maildir, user_newname); + newmailfile = xaprintf("%s/%s/%s", + prefix, maildir, user_newname); } else { - xasprintf(&newmailfile, "%s/%s", maildir, user_newname); + newmailfile = xaprintf("%s/%s", maildir, user_newname); } if ( (link (mailfile, newmailfile) != 0) || (unlink (mailfile) != 0)) { diff --git a/src/vipw.c b/src/vipw.c index b86eae5497..5d4a059523 100644 --- a/src/vipw.c +++ b/src/vipw.c @@ -45,7 +45,7 @@ #include "sssd.h" #include "string/sprintf/aprintf.h" #include "string/sprintf/snprintf.h" -#include "string/sprintf/xasprintf.h" +#include "string/sprintf/xaprintf.h" #include "string/strcmp/streq.h" @@ -308,7 +308,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void)) continue; } - xasprintf(&buf, "%s %s", editor, fileedit); + buf = xaprintf("%s %s", editor, fileedit); status = system (buf); if (-1 == status) {