Module Name:    src
Committed By:   rillig
Date:           Tue Jul 28 17:18:40 UTC 2020

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: varmisc.exp varmisc.mk

Log Message:
make(1): issue a parse error on unclosed variables

These errors had not been detected before by make.
In pkgsrc, this task as been done by pkglint since 2019-04-07.


To generate a diff of this commit:
cvs rdiff -u -r1.352 -r1.353 src/usr.bin/make/var.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/make/unit-tests/varmisc.exp
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/unit-tests/varmisc.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/var.c
diff -u src/usr.bin/make/var.c:1.352 src/usr.bin/make/var.c:1.353
--- src/usr.bin/make/var.c:1.352	Tue Jul 28 16:42:22 2020
+++ src/usr.bin/make/var.c	Tue Jul 28 17:18:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.352 2020/07/28 16:42:22 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.353 2020/07/28 17:18:40 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.352 2020/07/28 16:42:22 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.353 2020/07/28 17:18:40 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.352 2020/07/28 16:42:22 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.353 2020/07/28 17:18:40 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -3506,6 +3506,8 @@ Var_Parse(const char * const str, GNode 
 	} else if (*tstr == endc) {
 	    haveModifier = FALSE;
 	} else {
+	    Parse_Error(PARSE_FATAL, "Unclosed variable \"%s\"",
+			Buf_GetAll(&namebuf, NULL));
 	    /*
 	     * If we never did find the end character, return NULL
 	     * right now, setting the length to be the distance to

Index: src/usr.bin/make/unit-tests/varmisc.exp
diff -u src/usr.bin/make/unit-tests/varmisc.exp:1.13 src/usr.bin/make/unit-tests/varmisc.exp:1.14
--- src/usr.bin/make/unit-tests/varmisc.exp:1.13	Sun Jul 26 21:46:10 2020
+++ src/usr.bin/make/unit-tests/varmisc.exp	Tue Jul 28 17:18:40 2020
@@ -47,9 +47,24 @@ parse-dynamic: parse-dynamic parse-dynam
 parse-dynamic: parse-dynamic parse-dynamic after
 parse-dynamic: parse-dynamic parse-dynamic after
 varerror-unclosed:begin
+make: Unclosed variable ""
 
+make: Unclosed variable "UNCLOSED"
+
+make: Unclosed variable "UNCLOSED"
+
+make: Unclosed variable "PATTERN"
 make: Unclosed variable specification (expecting '}') for "UNCLOSED" (value "") modifier M
 
+make: Unclosed variable "param"
+make: Unclosed variable "UNCLOSED."
+
+
+make: Unclosed variable "UNCLOSED.1"
+
+make: Unclosed variable "UNCLOSED.2"
+
+make: Unclosed variable "UNCLOSED.3"
 
 varerror-unclosed:end
 exit status 0

Index: src/usr.bin/make/unit-tests/varmisc.mk
diff -u src/usr.bin/make/unit-tests/varmisc.mk:1.17 src/usr.bin/make/unit-tests/varmisc.mk:1.18
--- src/usr.bin/make/unit-tests/varmisc.mk:1.17	Sun Jul 26 21:46:10 2020
+++ src/usr.bin/make/unit-tests/varmisc.mk	Tue Jul 28 17:18:40 2020
@@ -1,4 +1,4 @@
-# $Id: varmisc.mk,v 1.17 2020/07/26 21:46:10 rillig Exp $
+# $Id: varmisc.mk,v 1.18 2020/07/28 17:18:40 rillig Exp $
 #
 # Miscellaneous variable tests.
 
@@ -191,11 +191,18 @@ parse-dynamic:
 	@echo $@: ${GB_TARGET} ${GB_MEMBER} ${GB_PREFIX} ${GB_ARCHIVE} ${GB_ALLSRC}
 	@echo $@: ${GL_TARGET} ${GL_MEMBER} ${GL_PREFIX} ${GL_ARCHIVE} ${GL_ALLSRC}
 
-# As of 2020-07-26, make does not complain about unclosed variables.
-# It does complain about unclosed variables when parsing modifiers though.
+# Since 2020-07-28, make complains about unclosed variables.
+# Before that, it had not complained about unclosed variables only when
+# parsing the modifiers, but not when parsing the variable name.
 varerror-unclosed:
 	@echo $@:begin
+	@echo $(
+	@echo $(UNCLOSED
 	@echo ${UNCLOSED
 	@echo ${UNCLOSED:M${PATTERN
 	@echo ${UNCLOSED.${param
+	@echo $
+.for i in 1 2 3
+	@echo ${UNCLOSED.${i}
+.endfor
 	@echo $@:end

Reply via email to