From b807ccf261c875f131cf276be85c153deaf79863 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Sat, 5 Sep 2015 17:45:55 -0700 Subject: [PATCH] Subject: zlib: Avoid shifts of negative values inflateMark The C standard says that bit shifts of negative integers is undefined. This casts to unsigned values to assure a known result. https://github.com/madler/zlib/commit/e54e1299404101a5a9d0cf5e45512b543967f958.patch --- win32port/zlib/inflate.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/win32port/zlib/inflate.c b/win32port/zlib/inflate.c index 5bec31e2..664c4b9c 100644 --- a/win32port/zlib/inflate.c +++ b/win32port/zlib/inflate.c @@ -1472,9 +1472,10 @@ z_streamp strm; { struct inflate_state FAR *state; - if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16; - state = (struct inflate_state FAR *)strm->state; - return ((long)(state->back) << 16) + - (state->mode == COPY ? state->length : - (state->mode == MATCH ? state->was - state->length : 0)); + if (strm == Z_NULL || strm->state == Z_NULL) + return (long)(((unsigned long)0 - 1) << 16); + state = (struct inflate_state FAR *)strm->state; + return (long)(((unsigned long)((long)state->back)) << 16) + + (state->mode == COPY ? state->length : + (state->mode == MATCH ? state->was - state->length : 0)); }