diff options
author | Mike Frysinger <vapier@gentoo.org> | 2011-01-12 21:58:08 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2011-01-12 21:58:08 +0000 |
commit | 39a3ae0a219ead81eeb3364aeafdd99a4cdefc6e (patch) | |
tree | edd94578e806522016a16111355f077e90441a57 /sim | |
parent | 1b05df007beb1cbcc8cd9fd28d82d614a75e9432 (diff) | |
download | gdb-39a3ae0a219ead81eeb3364aeafdd99a4cdefc6e.zip gdb-39a3ae0a219ead81eeb3364aeafdd99a4cdefc6e.tar.gz gdb-39a3ae0a219ead81eeb3364aeafdd99a4cdefc6e.tar.bz2 |
sim: check asprintf return values
These are the last sources of build warnings (asprintf usage) that I see.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'sim')
-rw-r--r-- | sim/common/ChangeLog | 11 | ||||
-rw-r--r-- | sim/common/sim-module.c | 3 | ||||
-rw-r--r-- | sim/common/sim-options.c | 7 | ||||
-rw-r--r-- | sim/common/sim-utils.c | 7 | ||||
-rw-r--r-- | sim/common/sim-watch.c | 7 |
5 files changed, 29 insertions, 6 deletions
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 2a1f5de..65e7114 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -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 diff --git a/sim/common/sim-module.c b/sim/common/sim-module.c index d686182..bb0e2d0 100644 --- a/sim/common/sim-module.c +++ b/sim/common/sim-module.c @@ -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; } } diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c index b94c0ac..8ad71e7 100644 --- a/sim/common/sim-options.c +++ b/sim/common/sim-options.c @@ -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++; diff --git a/sim/common/sim-utils.c b/sim/common/sim-utils.c index b76064e..1dbc4fb 100644 --- a/sim/common/sim-utils.c +++ b/sim/common/sim-utils.c @@ -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); diff --git a/sim/common/sim-watch.c b/sim/common/sim-watch.c index ccef4fe..022ca13 100644 --- a/sim/common/sim-watch.c +++ b/sim/common/sim-watch.c @@ -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); |