]> git.sur5r.net Git - i3/i3/commitdiff
fix third argument to strncat(), use smalloc(), use strlen(".old")+1
authorMichael Stapelberg <michael@stapelberg.de>
Sun, 28 Nov 2010 00:22:10 +0000 (01:22 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Sun, 28 Nov 2010 00:22:10 +0000 (01:22 +0100)
src/tree.c

index 947a8daaba91c3520089fa69136a2732823012f7..75f8c7cbfcb17289ed94b7aead5c47edfb482147 100644 (file)
@@ -29,9 +29,9 @@ bool tree_restore() {
     tree_append_json(globbed);
 
     size_t path_len = strlen(config.restart_state_path);
-    char *old_restart = malloc(path_len + 5);
-    strncpy(old_restart, config.restart_state_path, path_len + 5);
-    strncat(old_restart, ".old", path_len + 5);
+    char *old_restart = smalloc(path_len + strlen(".old") + 1);
+    strncpy(old_restart, config.restart_state_path, path_len + strlen(".old") + 1);
+    strncat(old_restart, ".old", strlen(".old") + 1);
     unlink(old_restart);
     rename(globbed, old_restart);
     free(globbed);