summaryrefslogtreecommitdiff
path: root/cpio
diff options
context:
space:
mode:
authorJoerg Sonnenberger <joerg@bec.de>2017-04-29 18:52:21 +0200
committerJoerg Sonnenberger <joerg@bec.de>2017-04-29 18:52:21 +0200
commitdc7ce6cbb30e5e489743bda22b9be83a44e78c05 (patch)
treea55c7a18d7ca73e43666735b7547211053dda2ad /cpio
parent30c744c4b498fa5081c58a3a219ed04e5630fb7b (diff)
downloadlibarchive-dc7ce6cbb30e5e489743bda22b9be83a44e78c05.tar.gz
Optimize string processing.
Diffstat (limited to 'cpio')
-rw-r--r--cpio/cpio.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/cpio/cpio.c b/cpio/cpio.c
index 16745517..5beedd0d 100644
--- a/cpio/cpio.c
+++ b/cpio/cpio.c
@@ -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)