diff options
| author | Martin Matuska <mm@FreeBSD.org> | 2026-01-05 20:08:25 +0000 |
|---|---|---|
| committer | Martin Matuska <mm@FreeBSD.org> | 2026-01-05 20:10:21 +0000 |
| commit | 01333e8c4dd7b5e2bb90cc773332613cf085ccf4 (patch) | |
| tree | d3695e6c5576083074ed3d96865707633a9d6028 /tar | |
| parent | bf3359d92128e09a91c702f7da132d329ffda123 (diff) | |
Diffstat (limited to 'tar')
| -rw-r--r-- | tar/subst.c | 16 | ||||
| -rw-r--r-- | tar/write.c | 5 |
2 files changed, 10 insertions, 11 deletions
diff --git a/tar/subst.c b/tar/subst.c index a466f65358a5..53497ad0d1a3 100644 --- a/tar/subst.c +++ b/tar/subst.c @@ -237,7 +237,7 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result, char isEnd = 0; do { - isEnd = *name == '\0'; + isEnd = *name == '\0'; if (regexec(&rule->re, name, 10, matches, 0)) break; @@ -293,13 +293,13 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result, realloc_strcat(result, rule->result + j); if (matches[0].rm_eo > 0) { - name += matches[0].rm_eo; - } else { - // We skip a character because the match is 0-length - // so we need to add it to the output - realloc_strncat(result, name, 1); - name += 1; - } + name += matches[0].rm_eo; + } else if (!isEnd) { + // We skip a character because the match is 0-length + // so we need to add it to the output + realloc_strncat(result, name, 1); + name += 1; + } } while (rule->global && !isEnd); // Testing one step after because sed et al. run 0-length patterns a last time on the empty string at the end } diff --git a/tar/write.c b/tar/write.c index 9e6c97b580b7..b39a397707ba 100644 --- a/tar/write.c +++ b/tar/write.c @@ -163,7 +163,7 @@ set_writer_options(struct bsdtar *bsdtar, struct archive *a) * a format or filters which are not added to * the archive write object. */ memcpy(p, IGNORE_WRONG_MODULE_NAME, module_len); - memcpy(p, writer_options, opt_len); + memcpy(p + module_len, writer_options, opt_len); r = archive_write_set_options(a, p); free(p); if (r < ARCHIVE_WARN) @@ -190,13 +190,12 @@ set_reader_options(struct bsdtar *bsdtar, struct archive *a) char *p; /* Set default write options. */ if ((p = malloc(module_len + opt_len)) == NULL) - if (p == NULL) lafe_errc(1, errno, "Out of memory"); /* Prepend magic code to ignore options for * a format or filters which are not added to * the archive write object. */ memcpy(p, IGNORE_WRONG_MODULE_NAME, module_len); - memcpy(p, reader_options, opt_len); + memcpy(p + module_len, reader_options, opt_len); r = archive_read_set_options(a, p); free(p); if (r < ARCHIVE_WARN) |
