seq: fix potential NULL ptr reference

asprintf(3) allocates memory, and there isn't any guarantee of success.

MFC after:	2 weeks
Obtained from:  OpenBSD
This commit is contained in:
Mariusz Zaborski 2022-09-30 19:36:04 +02:00
parent c5e957ad4f
commit 94c4f663ba

View file

@ -199,8 +199,12 @@ main(int argc, char *argv[])
* loop held true due to a rounding error and we still need to print
* 'last'.
*/
asprintf(&cur_print, fmt, cur);
asprintf(&last_print, fmt, last);
if (asprintf(&cur_print, fmt, cur) < 0) {
err(1, "asprintf");
}
if (asprintf(&last_print, fmt, last) < 0) {
err(1, "asprintf");
}
if (strcmp(cur_print, last_print) == 0 && cur != last_shown_value) {
fputs(last_print, stdout);
fputs(sep, stdout);