From 25373f4d5f5b211fb959937eb370a03e2bacd7b3 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 2 Jun 2024 09:56:40 +0100 Subject: make: restore warning about invalid macro name Commit 90c5352a9 (make: change how macros are read from the environment) was intended to ignore environment variables with invalid names. It had the unintended consequence of also ignoring macros with invalid names defined in makefiles. This was because such macros can have the same level (3) as those imported from the environment. Rather than use the level to detect importing from the environment add a flag to indicate this circumstance. --- miscutils/make.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/miscutils/make.c b/miscutils/make.c index 02da3611c..deb04ec88 100644 --- a/miscutils/make.c +++ b/miscutils/make.c @@ -226,8 +226,9 @@ struct macro { }; // Flags passed to setmacro() -#define M_IMMEDIATE 8 // immediate-expansion macro is being defined -#define M_VALID 16 // assert macro name is valid +#define M_IMMEDIATE 0x08 // immediate-expansion macro is being defined +#define M_VALID 0x10 // assert macro name is valid +#define M_ENVIRON 0x20 // macro imported from environment // Constants for PRAGMA. Order must match strings in set_pragma(). enum { @@ -781,9 +782,10 @@ setmacro(const char *name, const char *val, int level) { struct macro *mp; bool valid = level & M_VALID; + bool from_env = level & M_ENVIRON; bool immediate = level & M_IMMEDIATE; - level &= ~(M_IMMEDIATE | M_VALID); + level &= ~(M_IMMEDIATE | M_VALID | M_ENVIRON); mp = getmp(name); if (mp) { // Don't replace existing macro from a lower level @@ -798,7 +800,7 @@ setmacro(const char *name, const char *val, int level) if (!valid && !is_valid_macro(name)) { // Silently drop invalid names from the environment - if (level == 3) + if (from_env) return; #if ENABLE_FEATURE_MAKE_POSIX error("invalid macro name '%s'%s", name, @@ -2843,9 +2845,9 @@ process_macros(char **argv, int level) /* We want to process _most_ macro assignments. * There are exceptions for particular values from the - * environment (level 3). */ + * environment. */ idx = index_in_strings(SPECIAL_MACROS, *argv); - if (!(level == 3 && + if (!((level & M_ENVIRON) && (idx == MAKEFLAGS || idx == SHELL || (idx == CURDIR && !useenv && !POSIX_2017)))) { if (colon) { @@ -3084,7 +3086,7 @@ int make_main(int argc UNUSED_PARAM, char **argv) } // Process macro definitions from the environment - process_macros(environ, 3); + process_macros(environ, 3 | M_ENVIRON); // Update MAKEFLAGS and environment update_makeflags(); -- cgit v1.2.3-55-g6feb