Module Name:    src
Committed By:   rillig
Date:           Thu Jul  2 12:34:30 UTC 2020

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: cond-short.exp

Log Message:
make(1): fix edge case for evaluating unnecessary conditions


To generate a diff of this commit:
cvs rdiff -u -r1.225 -r1.226 src/usr.bin/make/var.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cond-short.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/var.c
diff -u src/usr.bin/make/var.c:1.225 src/usr.bin/make/var.c:1.226
--- src/usr.bin/make/var.c:1.225	Wed Jul  1 18:02:26 2020
+++ src/usr.bin/make/var.c	Thu Jul  2 12:34:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.225 2020/07/01 18:02:26 sjg Exp $	*/
+/*	$NetBSD: var.c,v 1.226 2020/07/02 12:34:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.225 2020/07/01 18:02:26 sjg Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.226 2020/07/02 12:34:30 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.225 2020/07/01 18:02:26 sjg Exp $");
+__RCSID("$NetBSD: var.c,v 1.226 2020/07/02 12:34:30 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -3860,16 +3860,11 @@ Var_Parse(const char *str, GNode *ctxt, 
 	    }
 	    /*
 	     * A variable inside a variable, expand.
-	     * If we really started looking at a variable
-	     * (str[0] == '$'), then force VARF_WANTRES
-	     * since we need the nested variable expanded to
-	     * get the correct name to lookup.
 	     */
 	    if (*tstr == '$') {
 		int rlen;
 		void *freeIt;
-		char *rval = Var_Parse(tstr, ctxt,
-		    flags|((*str == '$') ? VARF_WANTRES : 0),  &rlen, &freeIt);
+		char *rval = Var_Parse(tstr, ctxt, flags, &rlen, &freeIt);
 		if (rval != NULL) {
 		    Buf_AddBytes(&buf, strlen(rval), rval);
 		}
@@ -4015,7 +4010,7 @@ Var_Parse(const char *str, GNode *ctxt, 
      * return.
      */
     nstr = Buf_GetAll(&v->val, NULL);
-    if (strchr(nstr, '$') != NULL) {
+    if (strchr(nstr, '$') != NULL && (flags & VARF_WANTRES) != 0) {
 	nstr = Var_Subst(NULL, nstr, ctxt, flags);
 	*freePtr = nstr;
     }

Index: src/usr.bin/make/unit-tests/cond-short.exp
diff -u src/usr.bin/make/unit-tests/cond-short.exp:1.3 src/usr.bin/make/unit-tests/cond-short.exp:1.4
--- src/usr.bin/make/unit-tests/cond-short.exp:1.3	Thu Jul  2 10:36:58 2020
+++ src/usr.bin/make/unit-tests/cond-short.exp	Thu Jul  2 12:34:30 2020
@@ -1,7 +1,6 @@
 expected and
 expected and exists
 expected and empty
-unexpected VAR U11
 expected U23 condition
 expected VAR23
 expected or

Reply via email to