From bb054d95d0336f8d36c85c5f1d8a98f935a3c131 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Fri, 2 Feb 2024 16:13:24 -0800 Subject: [PATCH] Stop decoding in zran.c once request is satisfied. --- examples/zran.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/zran.c b/examples/zran.c index 9c3e5dc..d3f5a36 100644 --- a/examples/zran.c +++ b/examples/zran.c @@ -402,8 +402,12 @@ ptrdiff_t deflate_index_extract(FILE *in, struct deflate_index *index, // Update the appropriate count. if (offset) offset -= got; - else + else { left -= got; + if (left == 0) + // Request satisfied. + break; + } // If we're at the end of a gzip member and there's more to read, // continue to the next gzip member. @@ -450,7 +454,7 @@ ptrdiff_t deflate_index_extract(FILE *in, struct deflate_index *index, // Continue until we have the requested data, the deflate data has // ended, or an error is encountered. - } while (ret == Z_OK && left); + } while (ret == Z_OK); inflateEnd(&strm); // Return the number of uncompressed bytes read into buf, or the error.