summaryrefslogtreecommitdiff
path: root/usr.bin/make/parse.c
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2020-12-06 18:37:04 +0000
committerrillig <rillig@NetBSD.org>2020-12-06 18:37:04 +0000
commitf8d66196d38b1f41cbb0b9ecb63077685448e8bb (patch)
tree0cc4a9a14240a4abe4b8f77ffc83be4310927b8a /usr.bin/make/parse.c
parent3a5228cd8eb8d52282df40dfc44529dfa2142700 (diff)
make(1): fix undefined behavior in ParseEOF
Adding a number to a null pointer should have been caught by any Undefined Behavior Sanitizer, but apparently neither GCC nor Clang do this.
Diffstat (limited to 'usr.bin/make/parse.c')
-rw-r--r--usr.bin/make/parse.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index 7d262ebc8a6..6c79c6222a0 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.469 2020/12/05 19:46:04 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.470 2020/12/06 18:37:04 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.469 2020/12/05 19:46:04 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.470 2020/12/06 18:37:04 rillig Exp $");
/* types and constants */
@@ -2623,7 +2623,7 @@ ParseEOF(void)
ptr = curFile->nextbuf(curFile->nextbuf_arg, &len);
curFile->buf_ptr = ptr;
curFile->buf_freeIt = ptr;
- curFile->buf_end = ptr + len; /* XXX: undefined behavior if ptr == NULL */
+ curFile->buf_end = ptr == NULL ? NULL : ptr + len;
curFile->lineno = curFile->first_lineno;
if (ptr != NULL)
return TRUE; /* Iterate again */