ar: Simplify __archive_read_consume usage

The __archive_read_consume function is binary: Either all bytes are
consumed or a failure occurred. No partial consumption can occur.

Simplify its calls to clarify this.

While at it, adjust style of callers as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
This commit is contained in:
Tobias Stoeckmann committed 2026-06-29 17:12:30 +02:00
1 parent ce962f1425
commit 2876f4912b
1 file changed
+6 -18
+6 -18
View File
@@ -509,17 +509,9 @@ archive_read_format_ar_read_data(struct archive_read *a,
ar->entry_bytes_remaining -= bytes_read;
return (ARCHIVE_OK);
} else {
int64_t skipped = __archive_read_consume(a, ar->entry_padding);
if (skipped >= 0) {
ar->entry_padding -= skipped;
}
if (ar->entry_padding) {
if (skipped >= 0) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
"Truncated ar archive - failed consuming padding");
}
if (__archive_read_consume(a, ar->entry_padding) < 0)
return (ARCHIVE_FATAL);
}
ar->entry_padding = 0;
*buff = NULL;
*size = 0;
*offset = ar->entry_offset;
@@ -530,15 +522,11 @@ archive_read_format_ar_read_data(struct archive_read *a,
static int
archive_read_format_ar_skip(struct archive_read *a)
{
int64_t bytes_skipped;
struct ar* ar;
struct ar* ar = (struct ar *)(a->format->data);
ar = (struct ar *)(a->format->data);
bytes_skipped = __archive_read_consume(a,
ar->entry_bytes_remaining + ar->entry_padding
+ ar->entry_bytes_unconsumed);
if (bytes_skipped < 0)
if (__archive_read_consume(a,
ar->entry_bytes_remaining + ar->entry_padding +
ar->entry_bytes_unconsumed) < 0)
return (ARCHIVE_FATAL);
ar->entry_bytes_remaining = 0;