Fixed undefined behaviour in rfx decoder

(cherry picked from commit ef611d34d61c6590429c17db5c97f0a9a33147e8)
This commit is contained in:
akallabeth 2020-05-15 15:40:12 +02:00
parent 37158cd17f
commit f25c2f265e

View File

@ -282,7 +282,10 @@ int rfx_rlgr_decode(RLGR_MODE mode, const BYTE* pSrcData, UINT32 SrcSize, INT16*
break;
bs->mask = ((1 << kr) - 1);
code = (UINT16)((bs->accumulator >> (32 - kr)) & bs->mask);
if (kr > 0)
code = (UINT16)((bs->accumulator >> (32 - kr)) & bs->mask);
else
code = 0;
BitStream_Shift(bs, kr);
/* add (vk << kr) to code */
@ -390,7 +393,10 @@ int rfx_rlgr_decode(RLGR_MODE mode, const BYTE* pSrcData, UINT32 SrcSize, INT16*
break;
bs->mask = ((1 << kr) - 1);
code = (UINT16)((bs->accumulator >> (32 - kr)) & bs->mask);
if (kr > 0)
code = (UINT16)((bs->accumulator >> (32 - kr)) & bs->mask);
else
code = 0;
BitStream_Shift(bs, kr);
/* add (vk << kr) to code */
@ -477,7 +483,10 @@ int rfx_rlgr_decode(RLGR_MODE mode, const BYTE* pSrcData, UINT32 SrcSize, INT16*
break;
bs->mask = ((1 << nIdx) - 1);
val1 = ((bs->accumulator >> (32 - nIdx)) & bs->mask);
if (nIdx > 0)
val1 = ((bs->accumulator >> (32 - nIdx)) & bs->mask);
else
val1 = 0;
BitStream_Shift(bs, nIdx);
val2 = code - val1;