From 5c74ae8116306a126b946ac00ade5133d1595dd8 Mon Sep 17 00:00:00 2001 From: peterhillman Date: Wed, 19 Aug 2020 09:53:56 +1200 Subject: [PATCH] re-order shift/compare in FastHuf to prevent undefined shift overflow warning (#819) Signed-off-by: Peter Hillman Co-authored-by: Cary Phillips --- OpenEXR/IlmImf/ImfFastHuf.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/OpenEXR/IlmImf/ImfFastHuf.cpp b/OpenEXR/IlmImf/ImfFastHuf.cpp index c04b56e75b..1c95fc7774 100644 --- a/OpenEXR/IlmImf/ImfFastHuf.cpp +++ b/OpenEXR/IlmImf/ImfFastHuf.cpp @@ -538,18 +538,24 @@ FastHufDecoder::refill buffer |= bufferBack >> (64 - numBits); } - - bufferBack = bufferBack << numBits; - bufferBackNumBits -= numBits; - // - // We can have cases where the previous shift of bufferBack is << 64 - - // in which case no shift occurs. The bit count math still works though, - // so if we don't have any bits left, zero out bufferBack. + + // + // We can have cases where the previous shift of bufferBack is << 64 - + // this is an undefined operation but tends to create just zeroes. + // so if we won't have any bits left, zero out bufferBack insetad of computing the shift // - if (bufferBackNumBits == 0) + if (bufferBackNumBits <= numBits) + { bufferBack = 0; + }else + { + bufferBack = bufferBack << numBits; + } + bufferBackNumBits -= numBits; + + } //