Skip to content

Commit

Permalink
make: limit changes to pragmas
Browse files Browse the repository at this point in the history
The special target .PRAGMA could be used to set or reset pragmas.
Doing anything other than setting pragmas very early in execution
is likely to be problematic.

Limit the abilities of .PRAGMA:

- Specifying .PRAGMA with no prerequisites now does nothing:
  pragmas are not reset.

- The posix_2017 and posix_202x pragmas can only be used to change
  the enforced POSIX level from the default.  Any further attempt
  to change POSIX level results in a warning.

Adds 16-32 bytes.
  • Loading branch information
rmyorston committed Jun 10, 2024
1 parent 997961d commit a518a4f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions miscutils/make.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,10 @@ set_pragma(const char *name)
if (idx >= BIT_POSIX_2017) {
// POSIX level is stored in a separate variable.
// No bits in 'pragma' are used.
posix_level = idx - BIT_POSIX_2017;
if (posix_level == DEFAULT_POSIX_LEVEL)
posix_level = idx - BIT_POSIX_2017;
else if (posix_level != idx - BIT_POSIX_2017)
warning("unable to change POSIX level");
} else {
pragma |= 1 << idx;
}
Expand Down Expand Up @@ -693,10 +696,6 @@ addrule(struct name *np, struct depend *dp, struct cmd *cp, int flag)
if ((np->n_flag & N_SPECIAL) && !dp && !cp) {
if (strcmp(np->n_name, ".PHONY") == 0)
return;
#if ENABLE_FEATURE_MAKE_POSIX
if (strcmp(np->n_name, ".PRAGMA") == 0)
pragma = 0;
#endif
freerules(np->n_rule);
np->n_rule = NULL;
return;
Expand Down

0 comments on commit a518a4f

Please # to comment.