From: Collin Funk Date: Sat, 14 Feb 2026 22:48:45 +0000 (-0800) Subject: maint: seq,who: prefer xasprintf X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=131fad77ad374074e079184575bc59c95546c000;p=thirdparty%2Fcoreutils.git maint: seq,who: prefer xasprintf * src/seq.c (main): Use xasprintf instead of asprintf followed by a check if the allocation fails. * src/who.c (print_line): Likewise. --- diff --git a/src/seq.c b/src/seq.c index 1a3a40eb62..29c332da01 100644 --- a/src/seq.c +++ b/src/seq.c @@ -27,6 +27,7 @@ #include "full-write.h" #include "quote.h" #include "xstrtod.h" +#include "xvasprintf.h" /* Roll our own isfinite/isnan rather than using , so that we don't have to worry about linking -lm just for isfinite. */ @@ -683,16 +684,11 @@ main (int argc, char **argv) && 0 < step.value && step.value <= SEQ_FAST_STEP_LIMIT && !equal_width && !format_str && strlen (separator) == 1) { - char *s1; - char *s2; - if (all_digits_p (user_start)) - s1 = xstrdup (user_start); - else if (asprintf (&s1, "%0.Lf", first.value) < 0) - xalloc_die (); - if (! isfinite (last.value)) - s2 = xstrdup ("inf"); /* Ensure "inf" is used. */ - else if (asprintf (&s2, "%0.Lf", last.value) < 0) - xalloc_die (); + char *s1 = (all_digits_p (user_start) + ? xstrdup (user_start) : xasprintf ("%0.Lf", first.value)); + /* Ensure "inf" is used. */ + char *s2 = (! isfinite (last.value) + ? xstrdup ("inf") : xasprintf ("%0.Lf", last.value)); if (*s1 != '-' && *s2 != '-') seq_fast (s1, s2, step.value); diff --git a/src/who.c b/src/who.c index 65c9e67888..226e9ceb1f 100644 --- a/src/who.c +++ b/src/who.c @@ -35,6 +35,7 @@ #include "readutmp.h" #include "hard-locale.h" #include "quote.h" +#include "xvasprintf.h" #ifdef TTY_GROUP_NAME # include @@ -233,7 +234,6 @@ print_line (char const *user, const char state, char x_idle[1 + IDLESTR_LEN + 1]; char x_pid[1 + INT_STRLEN_BOUND (pid_t) + 1]; char *x_exitstr; - int err; mesg[1] = state; @@ -253,32 +253,29 @@ print_line (char const *user, const char state, else *x_exitstr = '\0'; - err = asprintf (&buf, - "%-8s" - "%s" - " %-12s" - " %-*s" - "%s" - "%s" - " %-8s" - "%s" - , - user ? user : " .", - include_mesg ? mesg : "", - line, - time_format_width, - time_str, - x_idle, - x_pid, - /* FIXME: it's not really clear whether the following - field should be in the short_output. A strict reading - of SUSv2 would suggest not, but I haven't seen any - implementations that actually work that way... */ - comment, - x_exitstr + buf = xasprintf ("%-8s" + "%s" + " %-12s" + " %-*s" + "%s" + "%s" + " %-8s" + "%s" + , + user ? user : " .", + include_mesg ? mesg : "", + line, + time_format_width, + time_str, + x_idle, + x_pid, + /* FIXME: it's not really clear whether the following + field should be in the short_output. A strict reading + of SUSv2 would suggest not, but I haven't seen any + implementations that actually work that way... */ + comment, + x_exitstr ); - if (err == -1) - xalloc_die (); { /* Remove any trailing spaces. */