From 60d847df0b9691b7cb38bfba41b9d6aafd97efc2 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 20 Feb 2014 00:28:17 -0500 Subject: sim: constify arg to sim_do_command It is rare for people to want to modify the cmd arg. In general, they really shouldn't be, but a few still do. For those who misbehave, dupe the string locally so they can bang on it. --- sim/rx/ChangeLog | 5 +++++ sim/rx/gdb-if.c | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'sim/rx') diff --git a/sim/rx/ChangeLog b/sim/rx/ChangeLog index 3ce615e..674b82e 100644 --- a/sim/rx/ChangeLog +++ b/sim/rx/ChangeLog @@ -1,3 +1,8 @@ +2014-03-10 Mike Frysinger + + * gdb-if.c (sim_do_command): Add const to cmd. Move args + to top and add const. Call strdup on cmd and free at end. + 2014-03-05 Mike Frysinger * gdb-if.c (sim_load): Add const to prog. diff --git a/sim/rx/gdb-if.c b/sim/rx/gdb-if.c index 77048a0..3ccea98 100644 --- a/sim/rx/gdb-if.c +++ b/sim/rx/gdb-if.c @@ -791,11 +791,12 @@ sim_stop_reason (SIM_DESC sd, enum sim_stop *reason_p, int *sigrc_p) } void -sim_do_command (SIM_DESC sd, char *cmd) +sim_do_command (SIM_DESC sd, const char *cmd) { - check_desc (sd); + const char *args; + char *p = strdup (cmd); - char *p = cmd; + check_desc (sd); /* Skip leading whitespace. */ while (isspace (*p)) @@ -808,7 +809,6 @@ sim_do_command (SIM_DESC sd, char *cmd) /* Null-terminate the command word, and record the start of any further arguments. */ - char *args; if (*p) { *p = '\0'; @@ -844,6 +844,8 @@ sim_do_command (SIM_DESC sd, char *cmd) else printf ("The 'sim' command expects either 'trace' or 'verbose'" " as a subcommand.\n"); + + free (p); } char ** -- cgit v1.1