summaryrefslogtreecommitdiff
path: root/expand.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2009-08-02 16:05:42 +0000
committerPaul Smith <psmith@gnu.org>2009-08-02 16:05:42 +0000
commita56bd7cd7bc9b2817d6154fd5f942afb00d79db2 (patch)
tree9330340bfd24da63b6bf280a1977bfc0f2d6d0a3 /expand.c
parentd9f50293fdd49cf75f10e8d8ddb17b861dabbba2 (diff)
downloadmake-a56bd7cd7bc9b2817d6154fd5f942afb00d79db2.tar.gz
- Fix Savannah bug #27093
- Fix Savannah bug #27143 - Fix Savannah bug #23960 - Fix Savannah bug #27148
Diffstat (limited to 'expand.c')
-rw-r--r--expand.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/expand.c b/expand.c
index dc4ea47f..b5d53384 100644
--- a/expand.c
+++ b/expand.c
@@ -438,7 +438,8 @@ variable_expand (const char *line)
char *
expand_argument (const char *str, const char *end)
{
- char *tmp;
+ char *tmp, *alloc = NULL;
+ char *r;
if (str == end)
return xstrdup("");
@@ -446,11 +447,20 @@ expand_argument (const char *str, const char *end)
if (!end || *end == '\0')
return allocated_variable_expand (str);
- tmp = alloca (end - str + 1);
+ if (end - str + 1 > 1000)
+ tmp = alloc = xmalloc (end - str + 1);
+ else
+ tmp = alloca (end - str + 1);
+
memcpy (tmp, str, end - str);
tmp[end - str] = '\0';
- return allocated_variable_expand (tmp);
+ r = allocated_variable_expand (tmp);
+
+ if (alloc)
+ free (alloc);
+
+ return r;
}
/* Expand LINE for FILE. Error messages refer to the file and line where
@@ -563,11 +573,6 @@ allocated_variable_expand_for_file (const char *line, struct file *file)
value = variable_expand_for_file (line, file);
-#if 0
- /* Waste a little memory and save time. */
- value = xrealloc (value, strlen (value))
-#endif
-
variable_buffer = obuf;
variable_buffer_length = olen;