]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Merge r9276 (the PuTTYtel session-saving assertion failure fix).
authorSimon Tatham <anakin@pobox.com>
Tue, 13 Sep 2011 07:35:55 +0000 (07:35 +0000)
committerSimon Tatham <anakin@pobox.com>
Tue, 13 Sep 2011 07:35:55 +0000 (07:35 +0000)
[originally from svn r9277]
[r9276 == 9da44eeb266f7c261e2f2c5787a2cb1407e55218]

settings.c

index 943fbf3e5dd0a1a02d5a44848cc023360af6f690..a783bfffe56bc2eaa46b024c11ffbf213abe2c51 100644 (file)
@@ -303,11 +303,11 @@ static void wprefs(void *sesskey, char *name,
     for (maxlen = i = 0; i < nvals; i++) {
        const char *s = val2key(mapping, nvals, array[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++) {
@@ -317,7 +317,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);