Module Name:    src
Committed By:   rillig
Date:           Fri Jul 31 19:06:33 UTC 2020

Modified Files:
        src/usr.bin/make: dir.c
        src/usr.bin/make/unit-tests: dir.exp

Log Message:
make(1): fix parsing of nested braces in dependency lines

Before, make could not parse {{thi,fou}r,fif}teen properly. It did
correctly split up the outer brace into "" + "{thi,fou}r,fif" + "teen",
but then, when expanding the inner braces, it interpreted the first
comma already as a separator, even though this comma was enclosed in
another set of braces.

This resulted in the wrong expansion "{thiteen", which produced the
error message.  The next word "fouteen" was produced since the parser
stopped at the next closing brace.  After this, parsing continued after
the closing brace, producing "rteen".  Finally, the last expansion was
the correct "fifteen".


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/make/dir.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/dir.exp

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/dir.c
diff -u src/usr.bin/make/dir.c:1.78 src/usr.bin/make/dir.c:1.79
--- src/usr.bin/make/dir.c:1.78	Fri Jul 31 17:41:35 2020
+++ src/usr.bin/make/dir.c	Fri Jul 31 19:06:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.78 2020/07/31 17:41:35 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.79 2020/07/31 19:06:33 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: dir.c,v 1.78 2020/07/31 17:41:35 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.79 2020/07/31 19:06:33 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.78 2020/07/31 17:41:35 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.79 2020/07/31 19:06:33 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -715,12 +715,13 @@ DirExpandCurly(const char *word, const c
 	 * Find the end of this piece of the clause.
 	 */
 	bracelevel = 0;
-	while (*cp != ',') {
-	    if (*cp == '{') {
-		bracelevel++;
-	    } else if ((*cp == '}') && (bracelevel-- <= 0)) {
+	while (*cp != '\0') {
+	    if ((*cp == ',' || *cp == '}') && bracelevel == 0)
 		break;
-	    }
+	    if (*cp == '{')
+		bracelevel++;
+	    if (*cp == '}')
+		bracelevel--;
 	    cp++;
 	}
 	/*

Index: src/usr.bin/make/unit-tests/dir.exp
diff -u src/usr.bin/make/unit-tests/dir.exp:1.1 src/usr.bin/make/unit-tests/dir.exp:1.2
--- src/usr.bin/make/unit-tests/dir.exp:1.1	Fri Jul 31 16:42:51 2020
+++ src/usr.bin/make/unit-tests/dir.exp	Fri Jul 31 19:06:33 2020
@@ -1,11 +1,9 @@
-make: Unterminated {} clause "thiteen"
 1
 2
 3
 4
 5
-make: don't know how to make fouteen (continuing)
-make: don't know how to make rteen (continuing)
+13
+14
 15
-`all' not remade because of errors.
 exit status 0

Reply via email to