When the first element in a preference list was unrecognised, PuTTY would
authorben <ben@cda61777-01e9-0310-a592-d414129be87e>
Mon, 12 Sep 2005 15:45:29 +0000 (15:45 +0000)
committerben <ben@cda61777-01e9-0310-a592-d414129be87e>
Mon, 12 Sep 2005 15:45:29 +0000 (15:45 +0000)
hang when reading it because strtok() kept getting the full list passed in.
Fix this, and add an assert() for an assumption documented in a comment while
I'm in the area.

git-svn-id: svn://svn.tartarus.org/sgt/putty@6294 cda61777-01e9-0310-a592-d414129be87e

settings.c

index c2fd1b4..45784a2 100644 (file)
@@ -2,6 +2,7 @@
  * settings.c: read and write saved sessions. (platform-independent)
  */
 
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include "putty.h"
@@ -172,6 +173,7 @@ static void gprefs(void *sesskey, char *name, char *def,
                   int *array)
 {
     char commalist[80];
+    char *tokarg = commalist;
     int n;
     unsigned long seen = 0;           /* bitmap for weeding dups etc */
     gpps(sesskey, name, def, commalist, sizeof(commalist));
@@ -181,7 +183,8 @@ static void gprefs(void *sesskey, char *name, char *def,
     do {
        int v;
        char *key;
-       key = strtok(n==0 ? commalist : NULL, ","); /* sorry */
+       key = strtok(tokarg, ","); /* sorry */
+       tokarg = NULL;
        if (!key) break;
        if (((v = key2val(mapping, nvals, key)) != -1) &&
            !(seen & 1<<v)) {
@@ -194,6 +197,7 @@ static void gprefs(void *sesskey, char *name, char *def,
     {
        int i;
        for (i = 0; i < nvals; i++) {
+           assert(mapping[i].v < 32);
            if (!(seen & 1<<mapping[i].v)) {
                array[n] = mapping[i].v;
                n++;