]> git.sur5r.net Git - i3/i3/blobdiff - libi3/resolve_tilde.c
resolve_tilde: strncpy + strlen is pointless (#3436)
[i3/i3] / libi3 / resolve_tilde.c
index a4e82873151199a8f89378607f485a3910dfec48..6dbf132fa7605d59e3c7f96c4ce7ae2c57e0e51f 100644 (file)
@@ -2,11 +2,11 @@
  * vim:ts=4:sw=4:expandtab
  *
  * i3 - an improved dynamic tiling window manager
- * © 2009-2015 Michael Stapelberg and contributors (see also: LICENSE)
+ * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
  *
  */
-
 #include "libi3.h"
+
 #include <err.h>
 #include <glob.h>
 #include <stdlib.h>
@@ -23,7 +23,7 @@ char *resolve_tilde(const char *path) {
     char *head, *tail, *result;
 
     tail = strchr(path, '/');
-    head = strndup(path, tail ? (size_t)(tail - path) : strlen(path));
+    head = sstrndup(path, tail ? (size_t)(tail - path) : strlen(path));
 
     int res = glob(head, GLOB_TILDE, NULL, &globbuf);
     free(head);
@@ -34,10 +34,11 @@ char *resolve_tilde(const char *path) {
         err(EXIT_FAILURE, "glob() failed");
     } else {
         head = globbuf.gl_pathv[0];
-        result = scalloc(strlen(head) + (tail ? strlen(tail) : 0) + 1);
-        strncpy(result, head, strlen(head));
-        if (tail)
-            strncat(result, tail, strlen(tail));
+        result = scalloc(strlen(head) + (tail ? strlen(tail) : 0) + 1, 1);
+        strcpy(result, head);
+        if (tail) {
+            strcat(result, tail);
+        }
     }
     globfree(&globbuf);