Function decompress_next_from() needs a pointer to a buffer and the buffer size as arguments. Interesting enough the function fill() that returns the buffer pointer happens to modify also the buffer size, stored in a variable at file scope. So we need to guarantee fill() is called before to use buffer size as argument in decompress_next_from() Signed-off-by: Marco Costalba <mcostalba@xxxxxxxxx> --- Patch to be applied above decompress helper series. Not to be pedantic, but have a function that gives two really coupled values, as a buffer pointer and the size, the first as return value and the second through a variable at file scope is not something you are going to see advertised in the programming books! Sorry for this little rant but this bug really made me crazy. With this patch 'make test' runs with success! builtin-unpack-objects.c | 3 ++- index-pack.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c index f1a4883..72293ec 100644 --- a/builtin-unpack-objects.c +++ b/builtin-unpack-objects.c @@ -68,7 +68,8 @@ static void *get_data(unsigned long size) decompress_into(&stream, buf, size); for (;;) { - int ret = decompress_next_from(&stream, fill(1), len, Z_NO_FLUSH); + void* tmp = fill(1); // fill() modifies len, so be sure is evaluated as first + int ret = decompress_next_from(&stream, tmp, len, Z_NO_FLUSH); use(len - stream.avail_in); if (stream.total_out == size && ret == Z_STREAM_END) break; diff --git a/index-pack.c b/index-pack.c index 30d7837..13b308d 100644 --- a/index-pack.c +++ b/index-pack.c @@ -173,7 +173,8 @@ static void *unpack_entry_data(unsigned long offset, unsigned long size) decompress_into(&stream, buf, size); for (;;) { - int ret = decompress_next_from(&stream, fill(1), input_len, Z_NO_FLUSH); + void* tmp = fill(1); // fill() modifies input_len, so be sure is evaluated as first + int ret = decompress_next_from(&stream, tmp, input_len, Z_NO_FLUSH); use(input_len - stream.avail_in); if (stream.total_out == size && ret == Z_STREAM_END) break; -- 1.5.4.rc2.95.g0eaa-dirty - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html