X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/52112bad8df0cb279c147dbeb42526aeeed07011..31393e34a75043e8b46834d284a08fc45402c707:/settings.c diff --git a/settings.c b/settings.c index 934f186f..af5a1b20 100644 --- a/settings.c +++ b/settings.c @@ -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);