]> git.sur5r.net Git - i3/i3/commitdiff
resolve_tilde: strncpy + strlen is pointless (#3436)
authorOrestis <orestisf1993@gmail.com>
Sun, 7 Oct 2018 18:26:37 +0000 (21:26 +0300)
committerMichael Stapelberg <stapelberg@users.noreply.github.com>
Sun, 7 Oct 2018 18:26:37 +0000 (20:26 +0200)
strlen already assumes that the string is NULL-terminated.

Like in https://github.com/i3/i3status/pull/312 but for whatever reason
gcc didn't warn about this here.

libi3/resolve_tilde.c

index 51d642db37ec37f3f1dc014f44d51b31dd324390..6dbf132fa7605d59e3c7f96c4ce7ae2c57e0e51f 100644 (file)
@@ -35,9 +35,10 @@ char *resolve_tilde(const char *path) {
     } else {
         head = globbuf.gl_pathv[0];
         result = scalloc(strlen(head) + (tail ? strlen(tail) : 0) + 1, 1);
-        strncpy(result, head, strlen(head));
-        if (tail)
-            strncat(result, tail, strlen(tail));
+        strcpy(result, head);
+        if (tail) {
+            strcat(result, tail);
+        }
     }
     globfree(&globbuf);