X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/4a693cfc5c3ee0e639bbee0215345e921715ab04..b473b52b4246ef404e9da6bdc306af5eff5ce58f:/settings.c diff --git a/settings.c b/settings.c index de69d660..af5a1b20 100644 --- a/settings.c +++ b/settings.c @@ -145,10 +145,8 @@ static int gppmap(void *handle, char *name, Conf *conf, int primary) /* * Start by clearing any existing subkeys of this key from conf. */ - for (val = conf_get_str_strs(conf, primary, NULL, &key); - val != NULL; - val = conf_get_str_strs(conf, primary, key, &key)) - conf_del_str_str(conf, primary, key); + while ((key = conf_get_str_nthstrkey(conf, primary, 0)) != NULL) + conf_del_str_str(conf, primary, key); /* * Now read a serialised list from the settings and unmarshal it @@ -384,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++) { @@ -399,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);