From 2a6054ad7d6c4bb753a8156e870dcbe129456425 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 13 Sep 2011 07:35:55 +0000 Subject: [PATCH] Merge r9276 (the PuTTYtel session-saving assertion failure fix). [originally from svn r9277] [r9276 == 9da44eeb266f7c261e2f2c5787a2cb1407e55218] --- settings.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/settings.c b/settings.c index 943fbf3e..a783bfff 100644 --- a/settings.c +++ b/settings.c @@ -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);