From: simon Date: Tue, 13 Sep 2011 07:35:14 +0000 (+0000) Subject: Fix assertion failure in wprefs() when the list is zero-length. Breaks X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/commitdiff_plain/eedb14ccbad88290f0f8627aa75971c9140642db Fix assertion failure in wprefs() when the list is zero-length. Breaks 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 --- 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);