From 7deb42aafdf547a3648f60ff04e0114c10a3d18d Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Sun, 2 Aug 2009 16:05:42 +0000 Subject: - Fix Savannah bug #27093 - Fix Savannah bug #27143 - Fix Savannah bug #23960 - Fix Savannah bug #27148 --- expand.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'expand.c') 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; -- cgit v1.2.3