summaryrefslogtreecommitdiff
path: root/libiberty
diff options
context:
space:
mode:
authoraldyh <aldyh@138bc75d-0d04-0410-961f-82ee72b054a4>2016-07-29 16:40:55 +0000
committeraldyh <aldyh@138bc75d-0d04-0410-961f-82ee72b054a4>2016-07-29 16:40:55 +0000
commitad23bd2681962c566e75597a6460b54e93261f0b (patch)
tree3d4145b4bb447027e2ff796ee99f67e8c5f563b3 /libiberty
parent07ce0c8a21dd7b0af168a82d30131ea9aad37c8c (diff)
downloadgcc-ad23bd2681962c566e75597a6460b54e93261f0b.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@238880 138bc75d-0d04-0410-961f-82ee72b054a4
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 6209195ab38..a2e49a12cea 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 fe639d18bd2..fa813998be3 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;
}