Module Name:    src
Committed By:   sjg
Date:           Tue Jan 31 07:00:59 UTC 2017

Modified Files:
        src/usr.bin/make: var.c

Log Message:
Use VAR_INTERNAL when calling ApplyModifiers for VAR_{CMD,GLOBAL} only.


To generate a diff of this commit:
cvs rdiff -u -r1.210 -r1.211 src/usr.bin/make/var.c

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.210 src/usr.bin/make/var.c:1.211
--- src/usr.bin/make/var.c:1.210	Mon Jan 30 02:46:20 2017
+++ src/usr.bin/make/var.c	Tue Jan 31 07:00:59 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.210 2017/01/30 02:46:20 sjg Exp $	*/
+/*	$NetBSD: var.c,v 1.211 2017/01/31 07:00:59 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.210 2017/01/30 02:46:20 sjg Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.211 2017/01/31 07:00:59 sjg 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.210 2017/01/30 02:46:20 sjg Exp $");
+__RCSID("$NetBSD: var.c,v 1.211 2017/01/31 07:00:59 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -3729,6 +3729,7 @@ char *
 Var_Parse(const char *str, GNode *ctxt, int flags,
 	  int *lengthPtr, void **freePtr)
 {
+    GNode	   *mctxt;
     const char	   *tstr;    	/* Pointer into str */
     Var		   *v;		/* Variable in invocation */
     Boolean 	    haveModifier;/* TRUE if have modifiers for the variable */
@@ -3746,6 +3747,12 @@ Var_Parse(const char *str, GNode *ctxt, 
     const char     *extramodifiers; /* extra modifiers to apply first */
     char	  name[2];
 
+    /*
+     * We can safely (and only need to?) use VAR_INTERNAL for modifiers
+     * (so correct $_ is found) if ctxt is any of VAR_CMD, VAR_GLOBAL
+     * or VAR_INTERNAL, otherwise leave it alone.
+     */
+    mctxt = (ctxt == VAR_GLOBAL || ctxt == VAR_CMD) ? VAR_INTERNAL : ctxt;
     *freePtr = NULL;
     extramodifiers = NULL;
     dynamic = FALSE;
@@ -3992,7 +3999,7 @@ Var_Parse(const char *str, GNode *ctxt, 
 	extraFree = NULL;
 	if (extramodifiers != NULL) {
 		nstr = ApplyModifiers(nstr, extramodifiers, '(', ')',
-				      v, ctxt, flags, &used, &extraFree);
+				      v, mctxt, flags, &used, &extraFree);
 	}
 
 	if (haveModifier) {
@@ -4000,7 +4007,7 @@ Var_Parse(const char *str, GNode *ctxt, 
 		tstr++;
 
 		nstr = ApplyModifiers(nstr, tstr, startc, endc,
-				      v, ctxt, flags, &used, freePtr);
+				      v, mctxt, flags, &used, freePtr);
 		tstr += used;
 		free(extraFree);
 	} else {

Reply via email to