]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
xar: use strrchr to find parent directories 3312/head
authordatauwu <datauwu@users.noreply.github.com>
Tue, 21 Jul 2026 09:43:15 +0000 (17:43 +0800)
committerdatauwu <datauwu@users.noreply.github.com>
Tue, 21 Jul 2026 09:43:15 +0000 (17:43 +0800)
Replace the manual pathname scan with strrchr when locating the
parent directory.

libarchive/archive_write_set_format_xar.c

index c3e444f7e2cec1067ae992a9073d0e4b73670f9b..60aca3b234205fb0827def847a8b0bae93f126ce 100644 (file)
@@ -2249,15 +2249,8 @@ file_gen_utility_names(struct archive_write *a, struct file *file)
                archive_strncpy(&(file->symlink), pp, len2);
                cleanup_backslash(file->symlink.s, file->symlink.length);
        }
-       /*
-        * - Count up directory elements.
-        * - Find out the position which points the last position of
-        *   path separator('/').
-        */
-       slash = NULL;
-       for (; *p != '\0'; p++)
-               if (*p == '/')
-                       slash = p;
+       /* Find the last path separator. */
+       slash = strrchr(p, '/');
        if (slash == NULL) {
                /* The pathname doesn't have a parent directory. */
                file->parentdir.length = len;