summaryrefslogtreecommitdiff
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
parente2f16fdf45ec0506c68f32e9fc6a7b31ae17fdc6 (diff)
downloadgunmake-7deb42aafdf547a3648f60ff04e0114c10a3d18d.tar.gz
- Fix Savannah bug #27093
- Fix Savannah bug #27143 - Fix Savannah bug #23960 - Fix Savannah bug #27148
-rw-r--r--ChangeLog12
-rw-r--r--doc/make.texi16
-rw-r--r--expand.c21
-rw-r--r--job.c2
-rw-r--r--variable.c23
5 files changed, 48 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index 3f0b073..26abd12 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2009-08-01 Paul Smith <psmith@gnu.org>
+
+ * expand.c (expand_argument): If the argument is large enough use
+ xmalloc() instead of alloca(). Fixes Savannah bug #27143.
+
+ * variable.c (do_variable_definition): Avoid using alloca() to
+ hold values, which can be large. Fixes Savannah bug #23960.
+
+ * job.c (new_job): Use memmove() instead of strcpy() since both
+ pointers are in the same memory block. Fixes Savannah bug #27148.
+ Patch by Petr Machata.
+
2009-07-29 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* job.c (construct_command_argv_internal): Add "ulimit" and
diff --git a/doc/make.texi b/doc/make.texi
index c036a6d..f73de46 100644
--- a/doc/make.texi
+++ b/doc/make.texi
@@ -8478,7 +8478,7 @@ for full details on suffix rules.
@pindex .o
@pindex .c
@file{@var{n}.o} is made automatically from @file{@var{n}.c} with
-a recipe of the form @samp{$(CC) -c $(CPPFLAGS) $(CFLAGS)}.@refill
+a recipe of the form @samp{$(CC) $(CPPFLAGS) $(CFLAGS) -c}.@refill
@item Compiling C++ programs
@cindex C++, rule to compile
@@ -8488,7 +8488,7 @@ a recipe of the form @samp{$(CC) -c $(CPPFLAGS) $(CFLAGS)}.@refill
@pindex .C
@file{@var{n}.o} is made automatically from @file{@var{n}.cc},
@file{@var{n}.cpp}, or @file{@var{n}.C} with a recipe of the form
-@samp{$(CXX) -c $(CPPFLAGS) $(CXXFLAGS)}. We encourage you to use the
+@samp{$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c}. We encourage you to use the
suffix @samp{.cc} for C++ source files instead of @samp{.C}.@refill
@item Compiling Pascal programs
@@ -8496,7 +8496,7 @@ suffix @samp{.cc} for C++ source files instead of @samp{.C}.@refill
@pindex pc
@pindex .p
@file{@var{n}.o} is made automatically from @file{@var{n}.p}
-with the recipe @samp{$(PC) -c $(PFLAGS)}.@refill
+with the recipe @samp{$(PC) $(PFLAGS) -c}.@refill
@item Compiling Fortran and Ratfor programs
@cindex Fortran, rule to compile
@@ -8511,11 +8511,11 @@ Fortran compiler. The precise recipe used is as follows:@refill
@table @samp
@item .f
-@samp{$(FC) -c $(FFLAGS)}.
+@samp{$(FC) $(FFLAGS) -c}.
@item .F
-@samp{$(FC) -c $(FFLAGS) $(CPPFLAGS)}.
+@samp{$(FC) $(FFLAGS) $(CPPFLAGS) -c}.
@item .r
-@samp{$(FC) -c $(FFLAGS) $(RFLAGS)}.
+@samp{$(FC) $(FFLAGS) $(RFLAGS) -c}.
@end table
@item Preprocessing Fortran and Ratfor programs
@@ -8526,9 +8526,9 @@ program. The precise recipe used is as follows:@refill
@table @samp
@item .F
-@samp{$(FC) -F $(CPPFLAGS) $(FFLAGS)}.
+@samp{$(FC) $(CPPFLAGS) $(FFLAGS) -F}.
@item .r
-@samp{$(FC) -F $(FFLAGS) $(RFLAGS)}.
+@samp{$(FC) $(FFLAGS) $(RFLAGS) -F}.
@end table
@item Compiling Modula-2 programs
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;
diff --git a/job.c b/job.c
index b52868f..a4dadb1 100644
--- a/job.c
+++ b/job.c
@@ -1600,7 +1600,7 @@ new_job (struct file *file)
/* There are no more references in this line to worry about.
Copy the remaining uninteresting text to the output. */
if (out != in)
- strcpy (out, in);
+ memmove (out, in, strlen (in) + 1);
/* Finally, expand the line. */
lines[i] = allocated_variable_expand_for_file (cmds->command_lines[i],
diff --git a/variable.c b/variable.c
index 92a96ec..10bbc54 100644
--- a/variable.c
+++ b/variable.c
@@ -1091,7 +1091,7 @@ do_variable_definition (const struct floc *flocp, const char *varname,
unsigned int oldlen, vallen;
const char *val;
- char *tp;
+ char *tp = NULL;
val = value;
if (v->recursive)
@@ -1104,15 +1104,17 @@ do_variable_definition (const struct floc *flocp, const char *varname,
when it was set; and from the expanded new value. Allocate
memory for the expansion as we may still need the rest of the
buffer if we're looking at a target-specific variable. */
- val = alloc_value = allocated_variable_expand (val);
+ val = tp = allocated_variable_expand (val);
oldlen = strlen (v->value);
vallen = strlen (val);
- tp = alloca (oldlen + 1 + vallen + 1);
- memcpy (tp, v->value, oldlen);
- tp[oldlen] = ' ';
- memcpy (&tp[oldlen + 1], val, vallen + 1);
- p = tp;
+ p = alloc_value = xmalloc (oldlen + 1 + vallen + 1);
+ memcpy (alloc_value, v->value, oldlen);
+ alloc_value[oldlen] = ' ';
+ memcpy (&alloc_value[oldlen + 1], val, vallen + 1);
+
+ if (tp)
+ free (tp);
}
}
}
@@ -1220,10 +1222,10 @@ do_variable_definition (const struct floc *flocp, const char *varname,
}
else
{
- if (alloc_value)
- free (alloc_value);
+ char *tp = alloc_value;
alloc_value = allocated_variable_expand (p);
+
if (find_and_set_default_shell (alloc_value))
{
v = define_variable_in_set (varname, strlen (varname), p,
@@ -1236,6 +1238,9 @@ do_variable_definition (const struct floc *flocp, const char *varname,
}
else
v = lookup_variable (varname, strlen (varname));
+
+ if (tp)
+ free (tp);
}
}
else