From: Mark Adler Date: Sun, 6 Sep 2015 00:45:55 +0000 (-0700) Subject: Avoid shifts of negative values inflateMark(). X-Git-Tag: v2.0.0-RC1~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6a27bda7f73beb5f7c638ef5db9846b3d51941f;p=thirdparty%2Fzlib-ng.git 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. --- diff --git a/inflate.c b/inflate.c index 36fc79c5..96f7443e 100644 --- a/inflate.c +++ b/inflate.c @@ -1337,7 +1337,8 @@ long Z_EXPORT PREFIX(inflateMark)(PREFIX3(stream) *strm) { return -65536; INFLATE_MARK_HOOK(strm); /* hook for IBM Z DFLTCC */ state = (struct inflate_state *)strm->state; - return ((long)(state->back) << 16) + (state->mode == COPY ? state->length : + return (long)(((unsigned long)((long)state->back)) << 16) + + (state->mode == COPY ? state->length : (state->mode == MATCH ? state->was - state->length : 0)); }