summaryrefslogtreecommitdiff
path: root/src/expand.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2021-03-15 01:09:32 -0400
committerPaul Smith <psmith@gnu.org>2021-03-15 01:17:06 -0400
commit52056d7b2cb5c3c889096d2138b5b19124cdf6b0 (patch)
tree80f8a6042c858889c7d9ece11f765ea3862a47e9 /src/expand.c
parentc66ec5fa20d33abf134892520179e32c2728e9b8 (diff)
downloadmake-git-52056d7b2cb5c3c889096d2138b5b19124cdf6b0.tar.gz
Ensure variable_buffer is always set.
Initialize the global variable_buffer in main() so that it is never a null pointer. Then invoking variable_expand("") is never needed: simply use the variable_buffer pointer when we want to restart the variable buffer. The main point of this simplification is not to keep a separate pointer to the beginning of the buffer: this is dangerous because the buffer may be re-allocated. Instead always use the variable_buffer pointer itself. * src/variable.h (initialize_variable_output): Publish. * src/expand.c (initialize_variable_output): Remove static. * src/main.c (main): Initialize variable_buffer. * src/file.c (enter_prereqs): Don't call variable_expand("") and don't save a separate buffer pointer than might be outdated. (expand_deps): Ditto. * src/read.c (record_files): Ditto. * src/remake.c (library_search): Ditto.
Diffstat (limited to 'src/expand.c')
-rw-r--r--src/expand.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/expand.c b/src/expand.c
index 0b6bb255..6e5d6d85 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -71,10 +71,11 @@ variable_buffer_output (char *ptr, const char *string, size_t length)
return ptr + length;
}
-/* Return a pointer to the beginning of the variable buffer. */
+/* Return a pointer to the beginning of the variable buffer.
+ This is called from main() and it should never be null afterward. */
-static char *
-initialize_variable_output (void)
+char *
+initialize_variable_output ()
{
/* If we don't have a variable output buffer yet, get one. */
@@ -207,7 +208,7 @@ variable_expand_string (char *line, const char *string, size_t length)
if (length == 0)
{
variable_buffer_output (o, "", 1);
- return (variable_buffer);
+ return variable_buffer;
}
/* We need a copy of STRING: due to eval, it's possible that it will get