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: do not expand variable name from the comm...



details:   https://anonhg.NetBSD.org/src/rev/07ac165f6a31
branches:  trunk
changeset: 1018975:07ac165f6a31
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Feb 22 22:26:50 2021 +0000

description:
make: do not expand variable name from the command line twice in a row

When

1.  there is a global variable containing a dollar in its expanded name
    (very unlikely since there are lots of undocumented edge cases that
    make variable names containing dollar signs fragile), and

2.  after that (unlikely since that requires .MAKEFLAGS instead of a
    normal command line)

3.  there is a command line variable of the same name (again very
    unlikely since that variable name would contain a dollar sign as
    well in the expanded form),

the global variable would not be undefined as promised by the comments
since its name was expanded once more than intended.

Because of the two 'very unlikely' above, this edge case hopefully does
not affect any practical use cases.

Note that this is not about VAR.${param} (which has a dollar sign in its
unexpanded form), but about the case where param itself would expand to
a dollar sign, such as after param=$$.

diffstat:

 usr.bin/make/var.c |  9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diffs (31 lines):

diff -r 33d1b1179b3f -r 07ac165f6a31 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Mon Feb 22 22:04:28 2021 +0000
+++ b/usr.bin/make/var.c        Mon Feb 22 22:26:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.834 2021/02/22 21:43:57 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.835 2021/02/22 22:26:50 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.834 2021/02/22 21:43:57 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.835 2021/02/22 22:26:50 rillig Exp $");
 
 typedef enum VarFlags {
        VFL_NONE        = 0,
@@ -985,10 +985,9 @@
                         * added to SCOPE_GLOBAL, so delete it from there if
                         * needed. Otherwise -V name may show the wrong value.
                         *
-                        * See 'scope == SCOPE_GLOBAL' above.
+                        * See ExistsInCmdline.
                         */
-                       /* XXX: name is expanded for the second time */
-                       Var_DeleteExpand(SCOPE_GLOBAL, name);
+                       Var_Delete(SCOPE_GLOBAL, name);
                }
                v = VarAdd(name, val, scope, flags);
        } else {



Home | Main Index | Thread Index | Old Index