Correct regression introduced in ac021570

In ac021570, a series of 4 int8_t was cast into an int32_t t, by
casting each int8_t into a uint32_t and shifting by an appropriate
number of bits, then casting back into int32_t.

It seems on GCC, when casting a negative int8_t into a uint32_t,
the sign bit is extended into the rest of the value. So you can wind up
with different values based on whether the integer is constructed using
little-endian ordering or big-endian.

Since the goal of the code is to just check if the values are the same
or not, this is replaced with a memcmp call.
This commit is contained in:
John Regan 2022-07-16 16:48:59 -04:00
parent ac021570a3
commit b10947e9e9
1 changed files with 1 additions and 12 deletions

View File

@ -275,18 +275,7 @@ static inline void applyTnsCoeffPreProcessing (LinearPredictor& predictor, TnsDa
if (commonFlag != nullptr) *commonFlag &= (tnsData1.coeffResLow[n] == tnsData2.coeffResLow[n] && tnsData1.filterOrder[n] == tnsData2.filterOrder[n]);
if (commonFlag != nullptr && *commonFlag)
{
const int32_t coeff1 = (int32_t)
((uint32_t) tnsData1.coeff[n][0]) |
((uint32_t) tnsData1.coeff[n][1] << 8) |
((uint32_t) tnsData1.coeff[n][2] << 16) |
((uint32_t) tnsData1.coeff[n][3] << 24);
const int32_t coeff2 = (int32_t)
((uint32_t) tnsData2.coeff[n][0]) |
((uint32_t) tnsData2.coeff[n][1] << 8) |
((uint32_t) tnsData2.coeff[n][2] << 16) |
((uint32_t) tnsData2.coeff[n][3] << 24);
*commonFlag &= (coeff1 == coeff2);
*commonFlag &= (memcmp(tnsData1.coeff[n],tnsData2.coeff[n],sizeof(tnsData1.coeff[n])) == 0);
}
}