[FSE] Fix division by zero
When the primary normalization method fails, and `(1 << tableLog) == (maxSymbolValue + 1)`, and every symbol gets assigned normalized weight 1 or -1 in the first loop, then the next division can raise `SIGFPE`.
This commit is contained in:
@@ -394,6 +394,9 @@ static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count,
|
|||||||
}
|
}
|
||||||
ToDistribute = (1 << tableLog) - distributed;
|
ToDistribute = (1 << tableLog) - distributed;
|
||||||
|
|
||||||
|
if (ToDistribute == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if ((total / ToDistribute) > lowOne) {
|
if ((total / ToDistribute) > lowOne) {
|
||||||
/* risk of rounding to zero */
|
/* risk of rounding to zero */
|
||||||
lowOne = (U32)((total * 3) / (ToDistribute * 2));
|
lowOne = (U32)((total * 3) / (ToDistribute * 2));
|
||||||
|
|||||||
Reference in New Issue
Block a user