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
commit7deb42aafdf547a3648f60ff04e0114c10a3d18d (patch)
tree9330340bfd24da63b6bf280a1977bfc0f2d6d0a3 /expand.c
parente2f16fdf45ec0506c68f32e9fc6a7b31ae17fdc6 (diff)
downloadgunmake-7deb42aafdf547a3648f60ff04e0114c10a3d18d.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 dc4ea47..b5d5338 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;