]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sim/rx: fix an issue where we try to modify a const string
authorAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 28 Jan 2021 17:17:08 +0000 (17:17 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 8 Feb 2021 11:01:07 +0000 (11:01 +0000)
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
sim/rx/gdb-if.c

index f06403958228ac84e30509fa526fca3a0d2ad7fe..8d5f1d745e68225c472e84d08fcbaf307643aa72 100644 (file)
@@ -1,3 +1,7 @@
+2021-02-08  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb-if.c (sim_do_command): Work with a copy of the command.
+
 2021-02-08  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb-if.c (sim_memory_map): New function.
index 6f8bfbd1c50b554c8465cf6af4f37a20c5ca2b8a..55eb13d12ef2f3737086852b70b96f96f0c3a398 100644 (file)
@@ -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;