* server.c (handle_query) <qSupported>: Do two passes over the
authorPedro Alves <palves@redhat.com>
Tue, 1 Jun 2010 12:47:33 +0000 (12:47 +0000)
committerPedro Alves <palves@redhat.com>
Tue, 1 Jun 2010 12:47:33 +0000 (12:47 +0000)
qSupported string to avoid nesting strtok.

gdb/gdbserver/ChangeLog
gdb/gdbserver/server.c

index b7d0c0cfc3ff9418d804fba7413b88aeb0265aab..6d77af632fa7e7ca196e3a9d78c9a699f05960e4 100644 (file)
@@ -1,3 +1,8 @@
+2010-06-01  Pedro Alves  <pedro@codesourcery.com>
+
+       * server.c (handle_query) <qSupported>: Do two passes over the
+       qSupported string to avoid nesting strtok.
+
 2010-05-28  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        * Makefile.in (SFILES): Add $(srcdir)/proc-service.list.
index 75b9d886774ce32f1ddb745715b87fd5babf386a..25845a73c5ae497e6124f41e8159413899d45156 100644 (file)
@@ -1346,20 +1346,40 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
         feature will follow a ':', and latter features will follow
         ';'.  */
       if (*p == ':')
-       for (p = strtok (p + 1, ";");
-            p != NULL;
-            p = strtok (NULL, ";"))
-         {
-           if (strcmp (p, "multiprocess+") == 0)
-             {
-               /* GDB supports and wants multi-process support if
-                  possible.  */
-               if (target_supports_multi_process ())
-                 multi_process = 1;
-             }
-           else
-             target_process_qsupported (p);
-         }
+       {
+         char **qsupported = NULL;
+         int count = 0;
+         int i;
+
+         /* Two passes, to avoid nested strtok calls in
+            target_process_qsupported.  */
+         for (p = strtok (p + 1, ";");
+              p != NULL;
+              p = strtok (NULL, ";"))
+           {
+             count++;
+             qsupported = xrealloc (qsupported, count * sizeof (char *));
+             qsupported[count - 1] = xstrdup (p);
+           }
+
+         for (i = 0; i < count; i++)
+           {
+             p = qsupported[i];
+             if (strcmp (p, "multiprocess+") == 0)
+               {
+                 /* GDB supports and wants multi-process support if
+                    possible.  */
+                 if (target_supports_multi_process ())
+                   multi_process = 1;
+               }
+             else
+               target_process_qsupported (p);
+
+             free (p);
+           }
+
+         free (qsupported);
+       }
 
       sprintf (own_buf, "PacketSize=%x;QPassSignals+", PBUFSIZ - 1);