We shouldn't fork off a utmp helper subprocess when we aren't setuid,
[sgt/putty] / settings.c
index de69d66..af5a1b2 100644 (file)
@@ -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);