Module Name:    src
Committed By:   rillig
Date:           Sat Oct 31 23:01:23 UTC 2020

Modified Files:
        src/usr.bin/make: parse.c
        src/usr.bin/make/unit-tests: directive-include.exp directive-include.mk

Log Message:
make(1): fix off-by-one bug in ParseTrackInput (since 2015-11-26)


To generate a diff of this commit:
cvs rdiff -u -r1.415 -r1.416 src/usr.bin/make/parse.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-include.exp \
    src/usr.bin/make/unit-tests/directive-include.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.415 src/usr.bin/make/parse.c:1.416
--- src/usr.bin/make/parse.c:1.415	Sat Oct 31 21:52:56 2020
+++ src/usr.bin/make/parse.c	Sat Oct 31 23:01:23 2020
@@ -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 @@ ParseTrackInput(const char *name)
 	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] == ' '))

Index: src/usr.bin/make/unit-tests/directive-include.exp
diff -u src/usr.bin/make/unit-tests/directive-include.exp:1.2 src/usr.bin/make/unit-tests/directive-include.exp:1.3
--- src/usr.bin/make/unit-tests/directive-include.exp:1.2	Sat Oct 31 22:55:35 2020
+++ src/usr.bin/make/unit-tests/directive-include.exp	Sat Oct 31 23:01:23 2020
@@ -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
Index: src/usr.bin/make/unit-tests/directive-include.mk
diff -u src/usr.bin/make/unit-tests/directive-include.mk:1.2 src/usr.bin/make/unit-tests/directive-include.mk:1.3
--- src/usr.bin/make/unit-tests/directive-include.mk:1.2	Sat Oct 31 22:55:35 2020
+++ src/usr.bin/make/unit-tests/directive-include.mk	Sat Oct 31 23:01:23 2020
@@ -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
 

Reply via email to