diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2012-08-24 15:02:28 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2012-08-24 15:02:28 -0700 |
commit | aa566e86c46d2264bf623e51f5840bde642548ad (patch) | |
tree | ccb156a5103cc7e6ced71e88f444acdb0e12654e | |
parent | 17068938ce5544ec3728402abd39bf3c55aec113 (diff) | |
download | zlib-aa566e86c46d2264bf623e51f5840bde642548ad.tar.gz zlib-aa566e86c46d2264bf623e51f5840bde642548ad.tar.bz2 zlib-aa566e86c46d2264bf623e51f5840bde642548ad.zip |
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.
-rw-r--r-- | gzwrite.c | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -270,14 +270,16 @@ int ZEXPORT gzputc(file, c) | |||
270 | 270 | ||
271 | /* try writing to input buffer for speed (state->size == 0 if buffer not | 271 | /* try writing to input buffer for speed (state->size == 0 if buffer not |
272 | initialized) */ | 272 | initialized) */ |
273 | if (strm->avail_in == 0) | 273 | if (state->size) { |
274 | strm->next_in = state->in; | 274 | if (strm->avail_in == 0) |
275 | have = strm->next_in + strm->avail_in - state->in; | 275 | strm->next_in = state->in; |
276 | if (have < state->size) { | 276 | have = strm->next_in + strm->avail_in - state->in; |
277 | state->in[have] = c; | 277 | if (have < state->size) { |
278 | strm->avail_in++; | 278 | state->in[have] = c; |
279 | state->x.pos++; | 279 | strm->avail_in++; |
280 | return c & 0xff; | 280 | state->x.pos++; |
281 | return c & 0xff; | ||
282 | } | ||
281 | } | 283 | } |
282 | 284 | ||
283 | /* no room in buffer or not initialized, use gz_write() */ | 285 | /* no room in buffer or not initialized, use gz_write() */ |