git: 94c4f663bab5 - main - seq: fix potential NULL ptr reference

From: Mariusz Zaborski <oshogbo_at_FreeBSD.org>
Date: Sat, 01 Oct 2022 10:07:34 UTC
The branch main has been updated by oshogbo:

URL: https://cgit.FreeBSD.org/src/commit/?id=94c4f663bab58ec07584786dd76866011d5b2506

commit 94c4f663bab58ec07584786dd76866011d5b2506
Author:     Mariusz Zaborski <oshogbo@FreeBSD.org>
AuthorDate: 2022-09-30 17:36:04 +0000
Commit:     Mariusz Zaborski <oshogbo@FreeBSD.org>
CommitDate: 2022-10-01 10:05:03 +0000

    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
---
 usr.bin/seq/seq.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/usr.bin/seq/seq.c b/usr.bin/seq/seq.c
index 7559dbd9ce20..47ba0b7ce3af 100644
--- a/usr.bin/seq/seq.c
+++ b/usr.bin/seq/seq.c
@@ -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);