Skip to content

Commit

Permalink
re-order shift/compare in FastHuf to prevent undefined shift overflow…
Browse files Browse the repository at this point in the history
… warning (#819)

Signed-off-by: Peter Hillman <peterh@wetafx.co.nz>

Co-authored-by: Cary Phillips <cary@ilm.com>
  • Loading branch information
peterhillman and cary-ilm authored Aug 18, 2020
1 parent 2da1302 commit 5c74ae8
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions OpenEXR/IlmImf/ImfFastHuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;


}

//
Expand Down

0 comments on commit 5c74ae8

Please sign in to comment.