aboutsummaryrefslogtreecommitdiff
path: root/libiberty
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2016-07-29 16:40:55 +0000
committerAldy Hernandez <aldyh@gcc.gnu.org>2016-07-29 16:40:55 +0000
commitac631cbe7021105c7fb8438deaeef66fe544b9aa (patch)
tree3d4145b4bb447027e2ff796ee99f67e8c5f563b3 /libiberty
parentd51553e083cbed3f5c334573adc999654fb26df2 (diff)
downloadgcc-ac631cbe7021105c7fb8438deaeef66fe544b9aa.zip
gcc-ac631cbe7021105c7fb8438deaeef66fe544b9aa.tar.gz
gcc-ac631cbe7021105c7fb8438deaeef66fe544b9aa.tar.bz2
libiberty.h (MAX_ALLOCA_SIZE): New macro.
include/ * libiberty.h (MAX_ALLOCA_SIZE): New macro. libiberty/ * make-relative-prefix.c (make_relative_prefix_1): Fall back to malloc if alloca argument is greater than MAX_ALLOCA_SIZE. From-SVN: r238880
Diffstat (limited to 'libiberty')
-rw-r--r--libiberty/ChangeLog5
-rw-r--r--libiberty/make-relative-prefix.c11
2 files changed, 13 insertions, 3 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index 6209195..a2e49a1 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,8 @@
+2016-07-29 Aldy Hernandez <aldyh@redhat.com>
+
+ * make-relative-prefix.c (make_relative_prefix_1): Fall back to
+ malloc if alloca argument is greater than MAX_ALLOCA_SIZE.
+
2016-07-15 Jason Merrill <jason@redhat.com>
* cp-demangle.c (cplus_demangle_operators): Add f[lrLR].
diff --git a/libiberty/make-relative-prefix.c b/libiberty/make-relative-prefix.c
index fe639d1..fa81399 100644
--- a/libiberty/make-relative-prefix.c
+++ b/libiberty/make-relative-prefix.c
@@ -233,6 +233,7 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix,
int i, n, common;
int needed_len;
char *ret = NULL, *ptr, *full_progname;
+ char *alloc_ptr = NULL;
if (progname == NULL || bin_prefix == NULL || prefix == NULL)
return NULL;
@@ -256,7 +257,10 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix,
#ifdef HAVE_HOST_EXECUTABLE_SUFFIX
len += strlen (HOST_EXECUTABLE_SUFFIX);
#endif
- nstore = (char *) alloca (len);
+ if (len < MAX_ALLOCA_SIZE)
+ nstore = (char *) alloca (len);
+ else
+ alloc_ptr = nstore = (char *) malloc (len);
startp = endp = temp;
while (1)
@@ -312,12 +316,12 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix,
else
full_progname = strdup (progname);
if (full_progname == NULL)
- return NULL;
+ goto bailout;
prog_dirs = split_directories (full_progname, &prog_num);
free (full_progname);
if (prog_dirs == NULL)
- return NULL;
+ goto bailout;
bin_dirs = split_directories (bin_prefix, &bin_num);
if (bin_dirs == NULL)
@@ -395,6 +399,7 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix,
free_split_directories (prog_dirs);
free_split_directories (bin_dirs);
free_split_directories (prefix_dirs);
+ free (alloc_ptr);
return ret;
}