Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Unified Diff: libiberty/argv.c

Issue 124383005: GDB 7.6.50 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@upstream
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « libiberty/Makefile.in ('k') | libiberty/concat.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: libiberty/argv.c
diff --git a/libiberty/argv.c b/libiberty/argv.c
index ca53f91493dbfc82797c4f2411c27c5b9a7fead6..f2727e8de95db2d849f57e690e64a9dbc08853ff 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.
@@ -191,7 +184,7 @@ char **buildargv (const char *input)
if (input != NULL)
{
- copybuf = (char *) alloca (strlen (input) + 1);
+ copybuf = (char *) xmalloc (strlen (input) + 1);
/* Is a do{}while to always execute the loop once. Always return an
argv, even for null strings. See NOTES above, test case below. */
do
@@ -205,21 +198,12 @@ char **buildargv (const char *input)
if (argv == NULL)
{
maxargc = INITIAL_MAXARGC;
- nargv = (char **) malloc (maxargc * sizeof (char *));
+ nargv = (char **) xmalloc (maxargc * sizeof (char *));
}
else
{
maxargc *= 2;
- nargv = (char **) realloc (argv, maxargc * sizeof (char *));
- }
- if (nargv == NULL)
- {
- if (argv != NULL)
- {
- freeargv (argv);
- argv = NULL;
- }
- break;
+ nargv = (char **) xrealloc (argv, maxargc * sizeof (char *));
}
argv = nargv;
argv[argc] = NULL;
@@ -284,19 +268,15 @@ char **buildargv (const char *input)
}
}
*arg = EOS;
- argv[argc] = strdup (copybuf);
- if (argv[argc] == NULL)
- {
- freeargv (argv);
- argv = NULL;
- break;
- }
+ argv[argc] = xstrdup (copybuf);
argc++;
argv[argc] = NULL;
consume_whitespace (&input);
}
while (*input != EOS);
+
+ free (copybuf);
}
return (argv);
}
@@ -455,14 +435,7 @@ expandargv (int *argcp, char ***argvp)
file_argv = buildargv (buffer);
/* If *ARGVP is not already dynamically allocated, copy it. */
if (!argv_dynamic)
- {
- *argvp = dupargv (*argvp);
- if (!*argvp)
- {
- fputs ("\nout of memory\n", stderr);
- xexit (1);
- }
- }
+ *argvp = dupargv (*argvp);
/* Count the number of arguments. */
file_argc = 0;
while (file_argv[file_argc])
« no previous file with comments | « libiberty/Makefile.in ('k') | libiberty/concat.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698