Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make: fix double expansion when appending to a ...



details:   https://anonhg.NetBSD.org/src/rev/3a76be23727f
branches:  trunk
changeset: 950876:3a76be23727f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Feb 03 08:40:47 2021 +0000

description:
make: fix double expansion when appending to a new variable

diffstat:

 usr.bin/make/unit-tests/var-op-append.exp |   2 +-
 usr.bin/make/unit-tests/var-op-append.mk  |  14 ++++++--------
 usr.bin/make/unit-tests/varname-empty.exp |   2 +-
 usr.bin/make/var.c                        |  20 ++++++++++----------
 4 files changed, 18 insertions(+), 20 deletions(-)

diffs (111 lines):

diff -r fdcb14149b79 -r 3a76be23727f usr.bin/make/unit-tests/var-op-append.exp
--- a/usr.bin/make/unit-tests/var-op-append.exp Wed Feb 03 08:34:15 2021 +0000
+++ b/usr.bin/make/unit-tests/var-op-append.exp Wed Feb 03 08:40:47 2021 +0000
@@ -1,7 +1,7 @@
 Var_Parse: ${:U\$\$\$\$\$\$\$\$} with VARE_WANTRES
 Applying ${:U...} to "" (VARE_WANTRES, none, VES_UNDEF)
 Result of ${:U\$\$\$\$\$\$\$\$} is "$$$$$$$$" (VARE_WANTRES, none, VES_DEF)
-Global:VAR.$$$$ = dollars
+Global:VAR.$$$$$$$$ = dollars
 Global:.MAKEFLAGS =  -r -k -d v -d
 Global:.MAKEFLAGS =  -r -k -d v -d 0
 exit status 0
diff -r fdcb14149b79 -r 3a76be23727f usr.bin/make/unit-tests/var-op-append.mk
--- a/usr.bin/make/unit-tests/var-op-append.mk  Wed Feb 03 08:34:15 2021 +0000
+++ b/usr.bin/make/unit-tests/var-op-append.mk  Wed Feb 03 08:40:47 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: var-op-append.mk,v 1.7 2020/10/30 20:36:33 rillig Exp $
+# $NetBSD: var-op-append.mk,v 1.8 2021/02/03 08:40:47 rillig Exp $
 #
 # Tests for the += variable assignment operator, which appends to a variable,
 # creating it if necessary.
@@ -32,17 +32,15 @@
 .  error
 .endif
 
-# Try out how often the variable name is expanded when appending to a
-# nonexistent variable.
-# As of 2020-10-30, that's two times.
-# XXX: That's one time too often.
-# See Var_Append, the call to Var_Set.
+# Before var.c 1.793 from 2021-02-03, the variable name of a newly created
+# variable was expanded two times in a row, which was unexpected but
+# irrelevant in practice since variable names containing dollars lead to
+# strange side effects in several other places as well.
 .MAKEFLAGS: -dv
 VAR.${:U\$\$\$\$\$\$\$\$}+=    dollars
 .MAKEFLAGS: -d0
-.if ${VAR.${:U\$\$\$\$}} != "dollars"
+.if ${VAR.${:U\$\$\$\$\$\$\$\$}} != "dollars"
 .  error
 .endif
 
 all:
-       @:;
diff -r fdcb14149b79 -r 3a76be23727f usr.bin/make/unit-tests/varname-empty.exp
--- a/usr.bin/make/unit-tests/varname-empty.exp Wed Feb 03 08:34:15 2021 +0000
+++ b/usr.bin/make/unit-tests/varname-empty.exp Wed Feb 03 08:40:47 2021 +0000
@@ -20,7 +20,7 @@
 Global:delete .INCLUDEDFROMFILE (not found)
 Var_Set("", "default", ...) name expands to empty string - ignored
 Var_Set("", "assigned", ...) name expands to empty string - ignored
-Var_Set("", "appended", ...) name expands to empty string - ignored
+SetVar: variable name is empty - ignored
 Var_Set("", "", ...) name expands to empty string - ignored
 Var_Set("", "subst", ...) name expands to empty string - ignored
 Var_Set("", "shell-output", ...) name expands to empty string - ignored
diff -r fdcb14149b79 -r 3a76be23727f usr.bin/make/var.c
--- a/usr.bin/make/var.c        Wed Feb 03 08:34:15 2021 +0000
+++ b/usr.bin/make/var.c        Wed Feb 03 08:40:47 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.792 2021/02/03 08:08:18 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.793 2021/02/03 08:40:47 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.792 2021/02/03 08:08:18 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.793 2021/02/03 08:40:47 rillig Exp $");
 
 typedef enum VarFlags {
        VAR_NONE        = 0,
@@ -916,6 +916,12 @@
 {
        Var *v;
 
+       assert(val != NULL);
+       if (name[0] == '\0') {
+               DEBUG0(VAR, "SetVar: variable name is empty - ignored\n");
+               return;
+       }
+
        if (ctxt == VAR_GLOBAL) {
                v = VarFind(name, VAR_CMDLINE, FALSE);
                if (v != NULL) {
@@ -1034,12 +1040,7 @@
 void
 Global_Set(const char *name, const char *value)
 {
-       assert(value != NULL);
-
-       if (name[0] == '\0')
-               DEBUG0(VAR, "Variable name empty - ignored\n");
-       else
-               SetVar(name, value, VAR_GLOBAL, VAR_SET_NONE);
+       SetVar(name, value, VAR_GLOBAL, VAR_SET_NONE);
 }
 
 void
@@ -1093,8 +1094,7 @@
        v = VarFind(name, ctxt, ctxt == VAR_GLOBAL);
 
        if (v == NULL) {
-               /* XXX: name is expanded for the second time */
-               Var_Set(name, val, ctxt);
+               SetVar(name, val, ctxt, VAR_SET_NONE);
        } else if (v->flags & VAR_READONLY) {
                DEBUG1(VAR, "Ignoring append to %s since it is read-only\n",
                    name);



Home | Main Index | Thread Index | Old Index