]> git.lizzy.rs Git - zlib.git/commitdiff
Fix unintialized value bug in gzputc() introduced by const patches.
authorMark Adler <madler@alumni.caltech.edu>
Fri, 24 Aug 2012 22:02:28 +0000 (15:02 -0700)
committerMark Adler <madler@alumni.caltech.edu>
Fri, 24 Aug 2012 22:02:28 +0000 (15:02 -0700)
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.

gzwrite.c

index bf5791354c5107a7693242a7586d813eb06bc16a..f53aace491186bd4444d37bdd832307fb34fa218 100644 (file)
--- 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() */