Module Name: src
Committed By: rillig
Date: Sat Mar 29 12:02:41 UTC 2025
Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: moderrs.exp moderrs.mk
Log Message:
make: fix error message for unclosed expression
Even in an unclosed expression such as "${VAR:from=to", the modifier
":from=to" needs to be recognized as such, instead of giving an error
message about an "Unknown modifier ":from=to"".
To generate a diff of this commit:
cvs rdiff -u -r1.1148 -r1.1149 src/usr.bin/make/var.c
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/make/unit-tests/moderrs.exp
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/make/unit-tests/moderrs.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.1148 src/usr.bin/make/var.c:1.1149
--- src/usr.bin/make/var.c:1.1148 Sat Mar 29 11:51:53 2025
+++ src/usr.bin/make/var.c Sat Mar 29 12:02:40 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.1148 2025/03/29 11:51:53 rillig Exp $ */
+/* $NetBSD: var.c,v 1.1149 2025/03/29 12:02:40 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -128,7 +128,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1148 2025/03/29 11:51:53 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1149 2025/03/29 12:02:40 rillig Exp $");
/*
* Variables are defined using one of the VAR=value assignments. Their
@@ -3707,17 +3707,17 @@ IsSysVModifier(const char *p, char start
bool eqFound = false;
int depth = 1;
- while (*p != '\0' && depth > 0) {
+ while (*p != '\0') {
if (*p == '=') /* XXX: should also test depth == 1 */
eqFound = true;
- else if (*p == endc)
- depth--;
- else if (*p == startc)
+ else if (*p == endc) {
+ if (--depth == 0)
+ break;
+ } else if (*p == startc)
depth++;
- if (depth > 0)
- p++;
+ p++;
}
- return *p == endc && eqFound;
+ return eqFound;
}
/* :from=to */
Index: src/usr.bin/make/unit-tests/moderrs.exp
diff -u src/usr.bin/make/unit-tests/moderrs.exp:1.48 src/usr.bin/make/unit-tests/moderrs.exp:1.49
--- src/usr.bin/make/unit-tests/moderrs.exp:1.48 Sat Mar 29 11:51:54 2025
+++ src/usr.bin/make/unit-tests/moderrs.exp Sat Mar 29 12:02:41 2025
@@ -165,21 +165,13 @@ make: Unclosed expression, expecting '}'
while evaluating variable "FIB" with value ""
in command "@echo ${FIB:3"
in target "mod-sysv-parse-1"
-make: Unknown modifier "3="
+make: Unfinished modifier after "", expecting "}"
while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34"
in command "@echo ${FIB:3="
in target "mod-sysv-parse-2"
-make: Unclosed expression, expecting '}' for modifier "3="
- while evaluating variable "FIB" with value ""
- in command "@echo ${FIB:3="
- in target "mod-sysv-parse-2"
-make: Unknown modifier "3=x3"
+make: Unfinished modifier after "x3", expecting "}"
while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34"
in command "@echo ${FIB:3=x3"
in target "mod-sysv-parse-3"
-make: Unclosed expression, expecting '}' for modifier "3=x3"
- while evaluating variable "FIB" with value ""
- in command "@echo ${FIB:3=x3"
- in target "mod-sysv-parse-3"
1 1 2 x3 5 8 1x3 21 34
exit status 2
Index: src/usr.bin/make/unit-tests/moderrs.mk
diff -u src/usr.bin/make/unit-tests/moderrs.mk:1.42 src/usr.bin/make/unit-tests/moderrs.mk:1.43
--- src/usr.bin/make/unit-tests/moderrs.mk:1.42 Sat Mar 29 11:51:54 2025
+++ src/usr.bin/make/unit-tests/moderrs.mk Sat Mar 29 12:02:41 2025
@@ -1,4 +1,4 @@
-# $NetBSD: moderrs.mk,v 1.42 2025/03/29 11:51:54 rillig Exp $
+# $NetBSD: moderrs.mk,v 1.43 2025/03/29 12:02:41 rillig Exp $
#
# various modifier error tests
@@ -200,12 +200,10 @@ mod-sysv-parse-1:
# expect: make: Unclosed expression, expecting '}' for modifier "3"
@echo ${FIB:3
mod-sysv-parse-2:
-# expect: make: Unknown modifier "3="
-# expect: make: Unclosed expression, expecting '}' for modifier "3="
+# expect: make: Unfinished modifier after "", expecting "}"
@echo ${FIB:3=
mod-sysv-parse-3:
-# expect: make: Unknown modifier "3=x3"
-# expect: make: Unclosed expression, expecting '}' for modifier "3=x3"
+# expect: make: Unfinished modifier after "x3", expecting "}"
@echo ${FIB:3=x3
mod-sysv-parse-4:
@echo ${FIB:3=x3} # ok