Fix assertion failure in wprefs() when the list is zero-length. Breaks
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Tue, 13 Sep 2011 07:35:14 +0000 (07:35 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Tue, 13 Sep 2011 07:35:14 +0000 (07:35 +0000)
any session-save operation in PuTTYtel due to the empty GSS list.

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

settings.c

index 934f186..af5a1b2 100644 (file)
@@ -382,11 +382,11 @@ static void wprefs(void *sesskey, char *name,
        const char *s = val2key(mapping, nvals,
                                 conf_get_int_int(conf, primary, i));
        if (s) {
-            maxlen += 1 + strlen(s);
+            maxlen += (maxlen > 0 ? 1 : 0) + strlen(s);
         }
     }
 
-    buf = snewn(maxlen, char);
+    buf = snewn(maxlen + 1, char);
     p = buf;
 
     for (i = 0; i < nvals; i++) {
@@ -397,7 +397,8 @@ static void wprefs(void *sesskey, char *name,
        }
     }
 
-    assert(p - buf == maxlen - 1);     /* maxlen counted the NUL */
+    assert(p - buf == maxlen);
+    *p = '\0';
 
     write_setting_s(sesskey, name, buf);