[02/11] sim/rx: fix an issue where we try to modify a const string

Message ID 7d7067b97f1181f6554473fadb2a039f9986f60a.1612179773.git.andrew.burgess@embecosm.com
State New
Headers show
Series
  • fix build warnings for rx simulator
Related show

Commit Message

Andrew Burgess Feb. 1, 2021, 11:44 a.m.
While experimenting with switching on warnings for the rx simulator I
discovered this bug.  In sim_do_command we get passed a 'const char *'
argument.  We create a copy of this string to work with locally, but
then while processing this we accidentally switch back to reference
the original string.

sim/rx/ChangeLog:

	* gdb-if.c (sim_do_command): Work with a copy of the command.
---
 sim/rx/ChangeLog | 4 ++++
 sim/rx/gdb-if.c  | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

-- 
2.25.4

Patch

diff --git a/sim/rx/gdb-if.c b/sim/rx/gdb-if.c
index 6f8bfbd1c50..55eb13d12ef 100644
--- a/sim/rx/gdb-if.c
+++ b/sim/rx/gdb-if.c
@@ -804,13 +804,13 @@  sim_do_command (SIM_DESC sd, const char *cmd)
     p++;
 
   /* Find the extent of the command word.  */
-  for (p = cmd; *p; p++)
+  for (; *p != '\0'; p++)
     if (isspace (*p))
       break;
 
   /* Null-terminate the command word, and record the start of any
      further arguments.  */
-  if (*p)
+  if (*p != '\0')
     {
       *p = '\0';
       args = p + 1;