Sat Oct 31 23:01:23 2020 UTC ()
make(1): fix off-by-one bug in ParseTrackInput (since 2015-11-26)


(rillig)
diff -r1.415 -r1.416 src/usr.bin/make/parse.c
diff -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-include.exp
diff -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-include.mk

cvs diff -r1.415 -r1.416 src/usr.bin/make/parse.c (expand / switch to context diff)
--- src/usr.bin/make/parse.c 2020/10/31 21:52:56 1.415
+++ src/usr.bin/make/parse.c 2020/10/31 23:01:23 1.416
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.415 2020/10/31 21:52:56 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.416 2020/10/31 23:01:23 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.415 2020/10/31 21:52:56 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.416 2020/10/31 23:01:23 rillig Exp $");
 
 /* types and constants */
 
@@ -2366,7 +2366,7 @@
 	for (; old != NULL; old = strchr(old, ' ')) {
 	    if (*old == ' ')
 		old++;
-	    if (old >= ep)
+	    if (old > ep)
 		break;		/* cannot contain name */
 	    if (memcmp(old, name, name_len) == 0 &&
 		(old[name_len] == '\0' || old[name_len] == ' '))

cvs diff -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-include.exp (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/directive-include.exp 2020/10/31 22:55:35 1.2
+++ src/usr.bin/make/unit-tests/directive-include.exp 2020/10/31 23:01:23 1.3
@@ -1,7 +1,5 @@
 CondParser_Eval: ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null"
 lhs = "directive-include.mk null", rhs = "directive-include.mk null", op = !=
-CondParser_Eval: ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null null"
-lhs = "directive-include.mk null null", rhs = "directive-include.mk null null", op = !=
-CondParser_Eval: ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null null"
-lhs = "directive-include.mk null null", rhs = "directive-include.mk null null", op = !=
+CondParser_Eval: ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null"
+lhs = "directive-include.mk null", rhs = "directive-include.mk null", op = !=
 exit status 0

cvs diff -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-include.mk (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/directive-include.mk 2020/10/31 22:55:35 1.2
+++ src/usr.bin/make/unit-tests/directive-include.mk 2020/10/31 23:01:23 1.3
@@ -1,4 +1,4 @@
-# $NetBSD: directive-include.mk,v 1.2 2020/10/31 22:55:35 rillig Exp $
+# $NetBSD: directive-include.mk,v 1.3 2020/10/31 23:01:23 rillig Exp $
 #
 # Tests for the .include directive, which includes another file.
 
@@ -15,17 +15,10 @@
 .endif
 
 # Each file is recorded only once in the variable .MAKE.MAKEFILES.
-# XXX: As of 2020-10-31, the very last file can be repeated, due to an
-# off-by-one bug in ParseTrackInput.
+# Between 2015-11-26 and 2020-10-31, the very last file could be repeated,
+# due to an off-by-one bug in ParseTrackInput.
 .include "/dev/null"
-.if ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null null"
-.  error
-.endif
-
-# Since the file /dev/null is not only recorded at the very end of the
-# variable .MAKE.MAKEFILES, it is not added a third time.
-.include "/dev/null"
-.if ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null null"
+.if ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null"
 .  error
 .endif