From: Tobias Stoeckmann Date: Mon, 29 Apr 2024 20:05:44 +0000 (+0200) Subject: archive_match: Turn counter into flag (#2154) X-Git-Tag: v3.7.5~93 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=287e05d539fcb9bb2aab22844c161070199b6698;p=thirdparty%2Flibarchive.git archive_match: Turn counter into flag (#2154) When working with matches, the code does not care about the actual amount of times when it matched, but just if it matched so far at least once or never. Turning the counter into a boolean flag has the advantage that even insanely huge archives will never lead to integer overflow here. --- diff --git a/libarchive/archive_match.c b/libarchive/archive_match.c index b108ff0a7..3ab8eda36 100644 --- a/libarchive/archive_match.c +++ b/libarchive/archive_match.c @@ -46,7 +46,7 @@ struct match { struct match *next; - int matches; + int matched; struct archive_mstring pattern; }; @@ -725,12 +725,12 @@ path_excluded(struct archive_match *a, int mbs, const void *pathname) matched = NULL; for (match = a->inclusions.first; match != NULL; match = match->next){ - if (match->matches == 0 && + if (!match->matched && (r = match_path_inclusion(a, match, mbs, pathname)) != 0) { if (r < 0) return (r); a->inclusions.unmatched_count--; - match->matches++; + match->matched = 1; matched = match; } } @@ -753,11 +753,10 @@ path_excluded(struct archive_match *a, int mbs, const void *pathname) for (match = a->inclusions.first; match != NULL; match = match->next){ /* We looked at previously-unmatched inclusions already. */ - if (match->matches > 0 && + if (match->matched && (r = match_path_inclusion(a, match, mbs, pathname)) != 0) { if (r < 0) return (r); - match->matches++; return (0); } } @@ -880,7 +879,7 @@ match_list_unmatched_inclusions_next(struct archive_match *a, for (m = list->unmatched_next; m != NULL; m = m->next) { int r; - if (m->matches) + if (m->matched) continue; if (mbs) { const char *p; @@ -1794,7 +1793,7 @@ match_owner_name_mbs(struct archive_match *a, struct match_list *list, < 0 && errno == ENOMEM) return (error_nomem(a)); if (p != NULL && strcmp(p, name) == 0) { - m->matches++; + m->matched = 1; return (1); } } @@ -1815,7 +1814,7 @@ match_owner_name_wcs(struct archive_match *a, struct match_list *list, < 0 && errno == ENOMEM) return (error_nomem(a)); if (p != NULL && wcscmp(p, name) == 0) { - m->matches++; + m->matched = 1; return (1); } }