Sat Oct 31 11:34:30 2020 UTC ()
make(1): reduce the scope where recursive expressions are detected

Only the call to Var_Subst needs to be protected since the other
functions have nothing to do with expanding variables.


(rillig)
diff -r1.417 -r1.418 src/usr.bin/make/main.c
diff -r1.614 -r1.615 src/usr.bin/make/var.c

cvs diff -r1.417 -r1.418 src/usr.bin/make/main.c (expand / switch to context diff)
--- src/usr.bin/make/main.c 2020/10/31 09:35:58 1.417
+++ src/usr.bin/make/main.c 2020/10/31 11:34:30 1.418
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.417 2020/10/31 09:35:58 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.418 2020/10/31 11:34:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -118,7 +118,7 @@
 #include "trace.h"
 
 /*	"@(#)main.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: main.c,v 1.417 2020/10/31 09:35:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.418 2020/10/31 11:34:30 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	    "The Regents of the University of California.  "
@@ -1827,7 +1827,7 @@
 
 /* Produce a Fatal error message, then exit immediately.
  *
- * If jobs are running, waits for them to finish. */
+ * If jobs are running, wait for them to finish. */
 void
 Fatal(const char *fmt, ...)
 {

cvs diff -r1.614 -r1.615 src/usr.bin/make/var.c (expand / switch to context diff)
--- src/usr.bin/make/var.c 2020/10/31 09:57:47 1.614
+++ src/usr.bin/make/var.c 2020/10/31 11:34:30 1.615
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.614 2020/10/31 09:57:47 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.615 2020/10/31 11:34:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -129,7 +129,7 @@
 #include    "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.614 2020/10/31 09:57:47 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.615 2020/10/31 11:34:30 rillig Exp $");
 
 #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
 #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
@@ -3662,12 +3662,8 @@
 	    free(varname);
     }
 
-    if (v->flags & VAR_IN_USE) {
+    if (v->flags & VAR_IN_USE)
 	Fatal("Variable %s is recursive.", v->name);
-	/*NOTREACHED*/
-    } else {
-	v->flags |= VAR_IN_USE;
-    }
 
     /*
      * Before doing any modification, we have to make sure the value
@@ -3683,12 +3679,12 @@
 	VarEvalFlags nested_eflags = eflags;
 	if (DEBUG(LINT))
 	    nested_eflags &= ~(unsigned)VARE_UNDEFERR;
+	v->flags |= VAR_IN_USE;
 	(void)Var_Subst(nstr, ctxt, nested_eflags, &nstr);
+	v->flags &= ~(unsigned)VAR_IN_USE;
 	/* TODO: handle errors */
 	*freePtr = nstr;
     }
-
-    v->flags &= ~(unsigned)VAR_IN_USE;
 
     if (haveModifier || extramodifiers != NULL) {
 	void *extraFree;