Commit c8002b04 authored by Martin Storsjo's avatar Martin Storsjo

Avoid casting arbitrary values to an enum

The enum only contains the constant values 0, 1 and 2. This produces
the warning "comparison of constant 6 with expression of type
'PS_RESOLUTION' is always false" in clang for the first check
in the getNoBands function (but apparently not for the second one
even though mode>=3 shouldn't ever happen for a valid PS_RESOLUTION
value either). This could allow the compiler to completely remove
the conditions that shouldn't be able to occur even though they
actually are used and are necessary.

By passing the value as UINT instead, it is clear to the compiler
that all the checks are necessary.
parent b41a6f9e
...@@ -267,13 +267,13 @@ static const INT psBands[] = ...@@ -267,13 +267,13 @@ static const INT psBands[] =
PS_BANDS_MID PS_BANDS_MID
}; };
static INT getNoBands(PS_RESOLUTION mode) static INT getNoBands(UINT mode)
{ {
if(mode>=6) if(mode>=6)
return 0; return 0;
if(mode>=3) if(mode>=3)
mode = (PS_RESOLUTION)(mode-3); mode = mode-3;
return psBands[mode]; return psBands[mode];
} }
...@@ -524,7 +524,7 @@ static INT encodeIpdOpd(HANDLE_PS_OUT psOut, ...@@ -524,7 +524,7 @@ static INT encodeIpdOpd(HANDLE_PS_OUT psOut,
bitCnt += FDKsbrEnc_EncodeIpd( hBitBuf, bitCnt += FDKsbrEnc_EncodeIpd( hBitBuf,
psOut->ipd[env], psOut->ipd[env],
ipdLast, ipdLast,
getNoBands((PS_RESOLUTION)psOut->iidMode), getNoBands((UINT)psOut->iidMode),
psOut->deltaIPD[env], psOut->deltaIPD[env],
&error); &error);
...@@ -532,7 +532,7 @@ static INT encodeIpdOpd(HANDLE_PS_OUT psOut, ...@@ -532,7 +532,7 @@ static INT encodeIpdOpd(HANDLE_PS_OUT psOut,
bitCnt += FDKsbrEnc_EncodeOpd( hBitBuf, bitCnt += FDKsbrEnc_EncodeOpd( hBitBuf,
psOut->opd[env], psOut->opd[env],
opdLast, opdLast,
getNoBands((PS_RESOLUTION)psOut->iidMode), getNoBands((UINT)psOut->iidMode),
psOut->deltaOPD[env], psOut->deltaOPD[env],
&error ); &error );
} }
...@@ -661,7 +661,7 @@ INT FDKsbrEnc_WritePSBitstream(const HANDLE_PS_OUT psOut, ...@@ -661,7 +661,7 @@ INT FDKsbrEnc_WritePSBitstream(const HANDLE_PS_OUT psOut,
bitCnt += FDKsbrEnc_EncodeIid( hBitBuf, bitCnt += FDKsbrEnc_EncodeIid( hBitBuf,
psOut->iid[env], psOut->iid[env],
iidLast, iidLast,
getNoBands((PS_RESOLUTION)psOut->iidMode), getNoBands((UINT)psOut->iidMode),
(PS_IID_RESOLUTION)getIIDRes(psOut->iidMode), (PS_IID_RESOLUTION)getIIDRes(psOut->iidMode),
psOut->deltaIID[env], psOut->deltaIID[env],
&error ); &error );
...@@ -677,7 +677,7 @@ INT FDKsbrEnc_WritePSBitstream(const HANDLE_PS_OUT psOut, ...@@ -677,7 +677,7 @@ INT FDKsbrEnc_WritePSBitstream(const HANDLE_PS_OUT psOut,
bitCnt += FDKsbrEnc_EncodeIcc( hBitBuf, bitCnt += FDKsbrEnc_EncodeIcc( hBitBuf,
psOut->icc[env], psOut->icc[env],
iccLast, iccLast,
getNoBands((PS_RESOLUTION)psOut->iccMode), getNoBands((UINT)psOut->iccMode),
psOut->deltaICC[env], psOut->deltaICC[env],
&error); &error);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment