]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Remove two unnecessary strings from the tar state (#2345)
authorTim Kientzle <kientzle@acm.org>
Wed, 25 Sep 2024 02:12:11 +0000 (19:12 -0700)
committerGitHub <noreply@github.com>
Wed, 25 Sep 2024 02:12:11 +0000 (19:12 -0700)
`pax_global` is not used at all and can be removed.

`longname` is only used locally within one function, so convert it to a
local variable there.

libarchive/archive_read_support_format_tar.c

index ab0b20a7e1401af943d151c7f45cd0922fd0050e..739b8c6fcfe9edced94f9ae6a94048059582ab60 100644 (file)
@@ -123,8 +123,6 @@ struct tar {
        struct archive_string    entry_uname;
        struct archive_string    entry_gname;
        struct archive_string    entry_linkpath;
-       struct archive_string    longname;
-       struct archive_string    pax_global;
        struct archive_string    line;
        int                      pax_hdrcharset_utf8;
        int64_t                  entry_bytes_remaining;
@@ -298,8 +296,6 @@ archive_read_format_tar_cleanup(struct archive_read *a)
        archive_string_free(&tar->entry_gname);
        archive_string_free(&tar->entry_linkpath);
        archive_string_free(&tar->line);
-       archive_string_free(&tar->pax_global);
-       archive_string_free(&tar->longname);
        archive_string_free(&tar->localname);
        free(tar);
        (a->format->data) = NULL;
@@ -1178,13 +1174,16 @@ header_gnu_longname(struct archive_read *a, struct tar *tar,
     struct archive_entry *entry, const void *h, size_t *unconsumed)
 {
        int err;
+       struct archive_string longname;
 
-       err = read_body_to_string(a, tar, &(tar->longname), h, unconsumed);
-       if (err != ARCHIVE_OK)
-               return (err);
-       if (archive_entry_copy_pathname_l(entry, tar->longname.s,
-           archive_strlen(&(tar->longname)), tar->sconv) != 0)
-               err = set_conversion_failed_error(a, tar->sconv, "Pathname");
+       archive_string_init(&longname);
+       err = read_body_to_string(a, tar, &longname, h, unconsumed);
+       if (err == ARCHIVE_OK) {
+               if (archive_entry_copy_pathname_l(entry, longname.s,
+                   archive_strlen(&longname), tar->sconv) != 0)
+                       err = set_conversion_failed_error(a, tar->sconv, "Pathname");
+       }
+       archive_string_free(&longname);
        return (err);
 }