Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions gzwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) {
return state->again ? put - len : 0;
}
} while (len);
state->strm.next_in = state->in;
}

/* input was all buffered or compressed */
Expand Down Expand Up @@ -386,8 +387,11 @@ local int gz_vacate(gz_statep state) {
z_streamp strm;

strm = &(state->strm);
if (strm->next_in == NULL ||
strm->next_in + strm->avail_in <= state->in + state->size)
if (strm->next_in == NULL || strm->avail_in == 0) {
strm->next_in = state->in;
return 0;
}
if (strm->next_in + strm->avail_in <= state->in + state->size)
return 0;
(void)gz_comp(state, Z_NO_FLUSH);
if (strm->avail_in == 0) {
Expand Down Expand Up @@ -454,7 +458,7 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
}
if (strm->avail_in == 0)
strm->next_in = state->in;
next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in);
next = (char *)(strm->next_in + strm->avail_in);
next[state->size - 1] = 0;
#ifdef NO_vsnprintf
# ifdef HAS_vsprintf_void
Expand Down
20 changes: 20 additions & 0 deletions test/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,26 @@ static void test_gzio(const char *fname, Byte *uncompr, uLong uncomprLen) {
}

gzclose(file);

/* Test large buffer gzwrite followed immediately by gzprintf */
file = gzopen(fname, "wb");
if (file == NULL) {
fprintf(stderr, "gzopen error\n");
exit(1);
}
{
char large_buf[16384];
memset(large_buf, 'A', sizeof(large_buf));
if (gzwrite(file, large_buf, (unsigned)sizeof(large_buf)) != (int)sizeof(large_buf)) {
fprintf(stderr, "gzwrite err: %s\n", gzerror(file, &err));
exit(1);
}
}
if (gzprintf(file, "%s", "test") != 4) {
fprintf(stderr, "gzprintf after large gzwrite err: %s\n", gzerror(file, &err));
exit(1);
}
gzclose(file);
#endif
}

Expand Down