summaryrefslogtreecommitdiff
path: root/gzwrite.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2012-08-24 15:02:28 -0700
committerMark Adler <madler@alumni.caltech.edu>2012-08-24 15:02:28 -0700
commitaa566e86c46d2264bf623e51f5840bde642548ad (patch)
treeccb156a5103cc7e6ced71e88f444acdb0e12654e /gzwrite.c
parent17068938ce5544ec3728402abd39bf3c55aec113 (diff)
downloadzlib-aa566e86c46d2264bf623e51f5840bde642548ad.tar.gz
Fix unintialized value bug in gzputc() introduced by const patches.
Avoid the use of an uninitialized value when the write buffers have not been initialized. A recent change to avoid the use of strm-> next_in in order to resolve some const conflicts added the use of state->in in its place. This patch avoids the use of state->in when it is not initialized. Nothing bad would actually happen, since two variables set to the same unintialized value are subtracted. However valgrind was rightly complaining. So this fixes that.
Diffstat (limited to 'gzwrite.c')
-rw-r--r--gzwrite.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/gzwrite.c b/gzwrite.c
index bf57913..f53aace 100644
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -270,14 +270,16 @@ int ZEXPORT gzputc(file, c)
/* try writing to input buffer for speed (state->size == 0 if buffer not
initialized) */
- if (strm->avail_in == 0)
- strm->next_in = state->in;
- have = strm->next_in + strm->avail_in - state->in;
- if (have < state->size) {
- state->in[have] = c;
- strm->avail_in++;
- state->x.pos++;
- return c & 0xff;
+ if (state->size) {
+ if (strm->avail_in == 0)
+ strm->next_in = state->in;
+ have = strm->next_in + strm->avail_in - state->in;
+ if (have < state->size) {
+ state->in[have] = c;
+ strm->avail_in++;
+ state->x.pos++;
+ return c & 0xff;
+ }
}
/* no room in buffer or not initialized, use gz_write() */