Re: seq: check for asprintf failure

2022-02-22 Thread Todd C . Miller
On Wed, 23 Feb 2022 00:04:07 +0100, Theo Buehler wrote:

> Hard to hit. Nevertheless it seems better to error out than to
> crash in strcmp()

Sure.  OK millert@

 - todd



seq: check for asprintf failure

2022-02-22 Thread Theo Buehler
Hard to hit. Nevertheless it seems better to error out than to
crash in strcmp()

Index: seq.c
===
RCS file: /cvs/src/usr.bin/seq/seq.c,v
retrieving revision 1.3
diff -u -p -r1.3 seq.c
--- seq.c   22 Feb 2022 16:14:38 -  1.3
+++ seq.c   22 Feb 2022 16:23:08 -
@@ -195,8 +195,9 @@ main(int argc, char *argv[])
 * loop held true due to a rounding error and we still need to print
 * 'last'.
 */
-   asprintf(_print, fmt, cur);
-   asprintf(_print, fmt, last);
+   if (asprintf(_print, fmt, cur) == -1 ||
+   asprintf(_print, fmt, last) == -1)
+   err(1, "asprintf");
if (strcmp(cur_print, last_print) == 0 && cur != last_shown_value) {
if (cur != first)
fputs(sep, stdout);