]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sim: check asprintf return values
authorMike Frysinger <vapier@gentoo.org>
Wed, 12 Jan 2011 21:58:08 +0000 (21:58 +0000)
committerMike Frysinger <vapier@gentoo.org>
Wed, 12 Jan 2011 21:58:08 +0000 (21:58 +0000)
These are the last sources of build warnings (asprintf usage) that I see.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
sim/common/ChangeLog
sim/common/sim-module.c
sim/common/sim-options.c
sim/common/sim-utils.c
sim/common/sim-watch.c

index 2a1f5de9d9a0585d9f793c3a6ed22533619e9601..65e711493b9e8c71aba44ad601d28f64cbaa817b 100644 (file)
@@ -1,3 +1,14 @@
+2011-01-12  Mike Frysinger  <vapier@gentoo.org>
+
+       * sim-module.c (sim_pre_argv_init): Return SIM_RC_FAIL when asprintf
+       fails.
+       * sim-options.c (sim_parse_args): Issue an error and return SIM_RC_FAIL
+       when asprintf fails.
+       * sim-utils.c (sim_do_commandf): Issue an error and return when
+       asprintf fails.
+       * sim-watch.c (sim_watchpoint_install): Return SIM_RC_FAIL when
+       asprintf fails.
+
 2011-01-11  Mike Frysinger  <vapier@gentoo.org>
 
        * sim-memopt.c (do_memopt_add): Set nr_bytes to s.st_size before
index d686182a34bc10a68b01dc305923ce1767dda19f..bb0e2d0dd08c28867742b4b57fc5fb1308d56b1a 100644 (file)
@@ -88,7 +88,8 @@ sim_pre_argv_init (SIM_DESC sd, const char *myname)
     for (i = 0; i < MAX_NR_PROCESSORS; ++i)
       {
        char *name;
-       asprintf (&name, "cpu%d", i);
+       if (asprintf (&name, "cpu%d", i) < 0)
+         return SIM_RC_FAIL;
        CPU_NAME (STATE_CPU (sd, i)) = name;
       }
   }
index b94c0ac98c9ea41aab45124a56c99e6e5ab56d74..8ad71e7a76f5b1d7364fd9796983679ebd1df458 100644 (file)
@@ -621,7 +621,12 @@ sim_parse_args (SIM_DESC sd, char **argv)
                char *name;
                *lp = opt->opt;
                /* Prepend --<cpuname>- to the option.  */
-               asprintf (&name, "%s-%s", CPU_NAME (cpu), lp->name);
+               if (asprintf (&name, "%s-%s", CPU_NAME (cpu), lp->name) < 0)
+                 {
+                   sim_io_eprintf (sd, "internal error, out of memory");
+                   result = SIM_RC_FAIL;
+                   break;
+                 }
                lp->name = name;
                /* Dynamically assign `val' numbers for long options. */
                lp->val = i++;
index b76064ec21e4a6edf6fe4329f95a8b2eedbafb68..1dbc4fbdd599bd19e7bdcd69cab19404aa519fce 100644 (file)
@@ -336,7 +336,12 @@ sim_do_commandf (SIM_DESC sd,
   va_list ap;
   char *buf;
   va_start (ap, fmt);
-  vasprintf (&buf, fmt, ap);
+  if (vasprintf (&buf, fmt, ap) < 0)
+    {
+      sim_io_eprintf (sd, "%s: asprintf failed for `%s'\n",
+                     STATE_MY_NAME (sd), fmt);
+      return;
+    }
   sim_do_command (sd, buf);
   va_end (ap);
   free (buf);
index ccef4fe851c9062c9fb91e09b8cfdeb0d308ea4c..022ca13361592b142de06f21376833aafdbd179c 100644 (file)
@@ -412,9 +412,10 @@ sim_watchpoint_install (SIM_DESC sd)
            char *name;
            int nr = interrupt_nr * nr_watchpoint_types + type;
            OPTION *option = &int_options[nr];
-           asprintf (&name, "watch-%s-%s",
-                     watchpoint_type_to_str (sd, type),
-                     interrupt_nr_to_str (sd, interrupt_nr));
+           if (asprintf (&name, "watch-%s-%s",
+                         watchpoint_type_to_str (sd, type),
+                         interrupt_nr_to_str (sd, interrupt_nr)) < 0)
+             return SIM_RC_FAIL;
            option->opt.name = name;
            option->opt.has_arg = required_argument;
            option->opt.val = type_to_option (sd, type, interrupt_nr);