]> sjero.net Git - wget/commitdiff
Handle correctly some malloc failures.
authorGiuseppe Scrivano <gscrivano@gnu.org>
Thu, 23 Feb 2012 10:45:05 +0000 (11:45 +0100)
committerGiuseppe Scrivano <gscrivano@gnu.org>
Thu, 23 Feb 2012 10:45:05 +0000 (11:45 +0100)
src/ChangeLog
src/main.c

index 9364d54d0a531386868e3eac8612a1df79957706..13ab1ae701e09c4e06d96b81ea25b6fe70eb5353 100644 (file)
@@ -1,5 +1,7 @@
 2012-02-23  Giuseppe Scrivano  <giuseppe@southpole.se>
 
+       * main.c (main): Fail gracefully if `malloc' fails.
+
        * gnutls.c (wgnutls_read): Remove unused variables `timer' and `flags'.
 
 2012-02-17  Steven Schubiger  <stsc@member.fsf.org>
index 5aa528defbcbb0ef0b3cf30db3fb8ce4c6897c09..9eefc98fcfdc5392f920799067c499113f25f0af 100644 (file)
@@ -988,15 +988,20 @@ main (int argc, char **argv)
   for (i = 1; i < argc; i++)
     argstring_length += strlen (argv[i]) + 2 + 1;
   char *p = program_argstring = malloc (argstring_length * sizeof (char));
+  if (p == NULL)
+    {
+      fprintf (stderr, _("Memory allocation problem\n"));
+      exit (2);
+    }
   for (i = 1; i < argc; i++)
-  {
-    *p++ = '"';
-    int arglen = strlen (argv[i]);
-    memcpy (p, argv[i], arglen);
-    p += arglen;
-    *p++ = '"';
-    *p++ = ' ';
-  }
+    {
+      *p++ = '"';
+      int arglen = strlen (argv[i]);
+      memcpy (p, argv[i], arglen);
+      p += arglen;
+      *p++ = '"';
+      *p++ = ' ';
+    }
   *p = '\0';
 
   /* Load the hard-coded defaults.  */
@@ -1355,6 +1360,11 @@ for details.\n\n"));
 
   /* Fill in the arguments.  */
   url = alloca_array (char *, nurl + 1);
+  if (url == NULL)
+    {
+      fprintf (stderr, _("Memory allocation problem\n"));
+      exit (2);
+    }
   for (i = 0; i < nurl; i++, optind++)
     {
       char *rewritten = rewrite_shorthand_url (argv[optind]);