diff mbox

PATCH: PR binutils/14526: c++filt is crashed on large files

Message ID CAMe9rOoyCk7-so=U96ufS6F8kAS2KRT42_GfgFM5kJRMHNqYpw@mail.gmail.com
State New
Headers show

Commit Message

H.J. Lu Aug. 29, 2012, 12:55 a.m. UTC
On Tue, Aug 28, 2012 at 5:09 PM, Ian Lance Taylor <iant@google.com> wrote:
> On Tue, Aug 28, 2012 at 11:33 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>
>> buildargv uses alloca to allocate buffer, whose size may exceed stack
>> limit.  This patch replaces alloca with xmalloc/free.  OK to install?
>>
>> Thanks.
>>
>> H.J.
>> ---
>>         PR binutils/14526
>>         * argv.c (buildargv): Replace alloca with xmalloc/free.
>
> This is OK.
>
> Thanks.
>
> Consider also replacing strdup with xstrdup.  And there are other
> malloc calls that could become xmalloc.  I can't think of any way that
> this code would be used where it needs to degrade gracefully when
> short on memory.
>
> Ian

Here is a patch.  OK to install?

Thanks.

Comments

Ian Lance Taylor Aug. 29, 2012, 12:58 a.m. UTC | #1
On Tue, Aug 28, 2012 at 5:55 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>
> Here is a patch.  OK to install?
>
> Thanks.
>
> --
> H.J.
> ---
>         * argv.c (dupargv): Replace malloc with xmalloc.  Don't check
>         xmalloc return.
>         (buildargv): Likewise.
>         (expandargv): Don't check dupargv return.

This is OK.

Thanks.

Ian
diff mbox

Patch

diff --git a/libiberty/argv.c b/libiberty/argv.c
index ca53f91..a5fe0af 100644
--- a/libiberty/argv.c
+++ b/libiberty/argv.c
@@ -1,5 +1,5 @@ 
 /* Create and destroy argument vectors (argv's)
-   Copyright (C) 1992, 2001, 2010 Free Software Foundation, Inc.
+   Copyright (C) 1992, 2001, 2010, 2012 Free Software Foundation, Inc.
    Written by Fred Fish @ Cygnus Support

 This file is part of the libiberty library.
@@ -72,20 +72,13 @@  dupargv (char **argv)

   /* the vector */
   for (argc = 0; argv[argc] != NULL; argc++);
-  copy = (char **) malloc ((argc + 1) * sizeof (char *));
-  if (copy == NULL)
-    return NULL;
-
+  copy = (char **) xmalloc ((argc + 1) * sizeof (char *));
+
   /* the strings */
   for (argc = 0; argv[argc] != NULL; argc++)
     {
       int len = strlen (argv[argc]);
-      copy[argc] = (char *) malloc (len + 1);
-      if (copy[argc] == NULL)
-	{
-	  freeargv (copy);
-	  return NULL;
-	}
+      copy[argc] = (char *) xmalloc (len + 1);
       strcpy (copy[argc], argv[argc]);
     }
   copy[argc] = NULL;
@@ -149,7 +142,7 @@  remains unchanged.  The last element of the vector
is followed by a
 @code{NULL} element.

 All of the memory for the pointer array and copies of the string
-is obtained from @code{malloc}.  All of the memory can be returned to the
+is obtained from @code{xmalloc}.  All of the memory can be returned to the
 system with the single function call @code{freeargv}, which takes the
 returned result of @code{buildargv}, as it's argument.