]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Optimize string processing.
authorJoerg Sonnenberger <joerg@bec.de>
Sat, 29 Apr 2017 16:52:21 +0000 (18:52 +0200)
committerJoerg Sonnenberger <joerg@bec.de>
Sat, 29 Apr 2017 16:52:21 +0000 (18:52 +0200)
cpio/cpio.c

index 16745517049c03e6e0f597496c4e358814b07250..5beedd0d16bcf5b4bae0720f0bd63399f5acca57 100644 (file)
@@ -1195,12 +1195,15 @@ mode_pass(struct cpio *cpio, const char *destdir)
        struct lafe_line_reader *lr;
        const char *p;
        int r;
+       size_t destdir_len;
 
        /* Ensure target dir has a trailing '/' to simplify path surgery. */
-       cpio->destdir = malloc(strlen(destdir) + 8);
-       strcpy(cpio->destdir, destdir);
-       if (destdir[strlen(destdir) - 1] != '/')
-               strcat(cpio->destdir, "/");
+       destdir_len = strlen(destdir);
+       cpio->destdir = malloc(destdir_len + 8);
+       memcpy(cpio->destdir, destdir, destdir_len);
+       if (destdir_len == 0 || destdir[destdir_len - 1] != '/')
+               cpio->destdir[destdir_len++] = '/';
+       cpio->destdir[destdir_len++] = '\0';
 
        cpio->archive = archive_write_disk_new();
        if (cpio->archive == NULL)