Commit Graph

3812 Commits

Author SHA1 Message Date
rillig
bd691351f1 make(1): fix comment in test about null bytes in makefiles 2020-12-22 08:57:23 +00:00
rillig
e6d109f2d3 make(1): re-add improved assertion in ParseGetLine 2020-12-22 08:51:30 +00:00
rillig
9582eb4d33 make(1): remove assertion about lines ending with '\n'
It fails the NetBSD build.sh.
2020-12-22 08:31:13 +00:00
rillig
0c15097160 make(1): clean up after test opt-file 2020-12-22 08:23:12 +00:00
rillig
75fb9c6afb make(1): remove needless assignment to line_end in ParseGetLine 2020-12-22 08:10:39 +00:00
rillig
b46e8d7cf5 make(1): fix assertion failure for files without trailing newline
Previously, mmapped files didn't always have the final newline added.
Only those that ended at a page boundary did.

This confused ParseRawLine, which assumed (and since parse.c 1.510 from
moments ago also asserted) that every line ends with a newline, which
allows the code to assume that after a backslash, there is at least one
other character in the buffer, thereby preventing an out-of-bounds read.

This bug had been there at least since parse.c 1.170 from 2010-12-25
04:57:07, maybe even earlier, I didn't check.

Now line_end always points to the trailing newline, which allows
ParseGetLine to overwrite that character to end the string.
2020-12-22 08:05:08 +00:00
rillig
8a4190c0a5 make(1): fix commit number in tests for :gmtime and :localtime 2020-12-22 07:22:39 +00:00
rillig
9b03887383 make(1): prevent undefined behavior in loadfile_mmap
Reading a file without a trailing newline had resulted in an
out-of-bounds write, in the common case where the file is loaded via
mmap.
2020-12-22 06:48:33 +00:00
rillig
f2023805b3 make(1): remove excess newline from parse errors (since 2020-11-01)
For the modifiers :gmtime and :localtime, the excess newline had been
added in var.c 1.631 from 2020-10-31 21:40:20.

For the modifiers :range and :ts, the excess newline had been added in
var.c 1.635 from 2020-11-01 14:36:25.
2020-12-21 21:04:18 +00:00
rillig
ecb61f4a92 make(1): align tests for :localtime with those for :gmtime
These tests had been almost the same before, now they are as similar as
possible again.
2020-12-21 20:47:29 +00:00
rillig
23e24e814c make(1): move tests for :gmtime to parse time
It's easier to have both the expressions and the expected values in a
single file.  This also allows for flexible handling of multiple
acceptable outputs, in this case for 32-bit time_t.
2020-12-21 20:35:17 +00:00
sjg
2de15e97b5 Set default for .MAKE.OS once 2020-12-21 18:22:31 +00:00
rillig
8277081861 make(1): remove redundant parameters from ParseModifierPart 2020-12-21 02:38:57 +00:00
rillig
0743b63f41 make(1): fix garbled output for failed shell command (since 2020-12-20)
Passing a struct as printf argument for the %s conversion doesn't work.
On NetBSD-8.0-x86_64, the output looks normal, but on SunOS-5.9, the
output is garbled, containing bytes 0xFF and 0xFE.

This bug had been introduced in parse.c 1.507 from 2020-12-20 14:52:16.

Thanks to sjg for finding this bug so quickly.
2020-12-21 02:09:34 +00:00
rillig
fcd6900042 make(1): save a few memory allocations in variable expressions 2020-12-21 00:30:13 +00:00
rillig
e6694a528e make(1): switch memory handling from MFStr to FStr
This makes all intermediate strings constant.  For this simple
search-and-replace refactoring, all intermediate locations where the
"current value of the expression" was stored had to be of the type
MFStr.

Using FStr instead of MFStr allows to save a few memory allocations,
which will be done in the follow-up commits.
2020-12-21 00:20:58 +00:00
rillig
be2b5e4446 make(1): clean up memory management for expanding variable expressions
Previously, memory management had been split among several variables.
The general idea was very simple though.  The current value of the
expression needs to be kept in memory, and each modifier either keeps
that value or replaces it with its own newly allocated result, or
var_Error or varUndefined.

Using MFStr, it does not matter anymore that var_Error and varUndefined
are statically allocated since these are assigned using MFStr_InitRefer.

The complexity of the implementation is now closer to the actual
complexity.  Most probably the code can be simplified even more.
2020-12-21 00:11:29 +00:00
rillig
23688beebb make(1): add tests for :tW and :tw modifiers 2020-12-20 23:29:50 +00:00
rillig
b8f5741af7 make(1): use FStr for ApplyModifiersState.newVal
Memory management is still complicated in this area.  To clean this up,
the previous value of the expression needs to be converted to an MFStr
first, and later to an FStr.
2020-12-20 23:27:37 +00:00
rillig
26a72fc416 make(1): add tests for variable modifiers on trailing slashes 2020-12-20 22:57:40 +00:00
rillig
94f06ed7ea make(1): fix undefined behavior in meta_oodate
Do not increment a null pointer.

Do not assign to a variable twice in the same statement.  To be fair,
this may be safe because of the sequence point when the function is
called, but anyway, it looks too close to undefined behavior.
2020-12-20 22:36:40 +00:00
rillig
06ccd6ce96 make(1): reduce scope of cp in meta_oodate
That function is way too long (550 lines) and has too creative variable
names such as fname, fname1, fname2, fname3.
2020-12-20 22:12:36 +00:00
rillig
4b4d56707b make(1): fix declared variable type in printCMDs
No functional changes since StringListNode and GNodeListNode are both
typedefs of a simple generic ListNode.
2020-12-20 22:02:54 +00:00
rillig
5196cc55b0 make(1): omit linear search for command in Compat_RunCommand 2020-12-20 21:07:32 +00:00
rillig
7a800efcdb make(1): remove redundant assignment in ApplyModifier_SysV 2020-12-20 19:51:37 +00:00
rillig
00ba7da94c make(1): error out on unknown variable modifiers at parse time
Before, make printed an "error message" that did not include the word
error and thus was not easily identified as such.  This "error message"
also did not influence the exit status in the default mode but only in
-dL mode.  The error message also didn't include any line number
information and was thus rude.
2020-12-20 19:47:34 +00:00
rillig
d52e9b267b make(1): include line numbers in output of test varmod-edge.mk
Suppressing the line numbers does not provide much benefit, given that
the test file doesn't change often.
2020-12-20 19:37:23 +00:00
rillig
374368e991 make(1): move tests for indirect modifiers around
The next commit will error out on unknown modifiers and influence the
exit status.  The test modmisc.mk contains both parse time tests and run
time tests.  To prevent the latter from being run, the parse error is
moved to varmod-indirect.mk, which only contains parse time tests.
2020-12-20 19:29:06 +00:00
rillig
b1b3d2f62b make(1): remove wrong error message for indirect modifier in lint mode 2020-12-20 19:10:53 +00:00
rillig
4938cf88d2 make(1): document that indirect modifiers fall back to SysV modifiers 2020-12-20 19:02:28 +00:00
rillig
9c42de2852 make(1): remove redundant const declarations for parameters 2020-12-20 18:23:24 +00:00
rillig
ffd320932f make(1): extract ApplySingleModifier from ApplyModifiers 2020-12-20 18:13:50 +00:00
rillig
e2fd21af29 make(1): turn ApplyModifiersState.val into a local variable
This reduces the scope and makes it more obvious at which places this
variable can be changed and how the memory management is done.
2020-12-20 17:22:10 +00:00
rillig
0e4ce27167 make(1): use FStr for memory management in Var_SetWithFlags 2020-12-20 15:31:29 +00:00
rillig
fa8bd88f04 make(1): extract SetVar from Var_SetWithFlags
SetVar contains the part that is not concerned about memory management
and expansion of the variable name.
2020-12-20 15:26:40 +00:00
rillig
eb277e70f2 make(1): fix memory leak in Var_Delete (since yesterday)
The memory leak had been introduced in var.c 1.736 from 2020-12-19
20:47:24.
2020-12-20 15:04:29 +00:00
rillig
80fba7d531 make(1): clean up memory handling in VarAssign_EvalShell 2020-12-20 14:52:16 +00:00
rillig
0b4b42e295 make(1): clean up memory handling in Parse_DoVar 2020-12-20 14:48:35 +00:00
rillig
431ba0ec4b make(1): remove constant parameter from MakeMode 2020-12-20 14:39:46 +00:00
rillig
0307413016 make(1): change return type of Var_Value to FStr 2020-12-20 14:32:13 +00:00
rillig
0462095db2 make(1): use FStr in VarNew 2020-12-20 13:50:10 +00:00
rillig
03f1822098 make(1): eliminate libName_freeIt from Arch_ParseArchive 2020-12-20 13:46:27 +00:00
rillig
7b3d8cbe3a make(1): return FStr from Var_Parse
This reduces the number of variable declarations at the call sites.
2020-12-20 13:38:43 +00:00
rillig
49eb293fd6 make(1): clean up memory handling in CondParser_String 2020-12-20 13:03:48 +00:00
rillig
81b5e18281 make(1): export FStr and MFStr
These types are a replacement for the pattern "var + var_freeIt" that
enforces these two variables to be updated together.
2020-12-20 12:53:34 +00:00
rillig
37fbcac361 make(1): clean up memory handling in CondParser_String 2020-12-20 12:46:49 +00:00
rillig
8f72c319f5 make(1): document memory handling in ApplyModifiers 2020-12-20 11:38:51 +00:00
rillig
0af8f23f02 make(1): replace freeIt with FStr in EvalUndefined
Previously, the parameter out_freeIt was not guaranteed to be
initialized in every case, at least when looking only at EvalUndefined.
This contradicted the variable name.

Replace the two parameters with a single FStr to ensure that these
variables are always initialized together.
2020-12-20 10:59:21 +00:00
rillig
19824f4691 make(1): replace FStr_Assign with separate initialization functions
In GetVarnamesToUnexport, there is no need to free the local FStr since
the only place where it is assigned an allocated string is at the very
end.

Having separate functions for the two main use cases of a possibly
allocated string makes the calling code simpler.  This is a preparatory
commit for making the memory allocation in ApplyModifiers easier to
understand.
2020-12-20 00:57:29 +00:00
rillig
e0de850d21 make(1): extract string functions from ApplyModifier_To 2020-12-20 00:47:21 +00:00