1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Fix strtol multiplication overflow check.

This commit is contained in:
Jonas 'Sortie' Termansen 2015-10-11 23:24:35 +02:00
parent f0f82fcb23
commit 8a653584c4

View file

@ -116,9 +116,9 @@ static bool would_multiplication_overflow(T_INT a, T_INT b)
T_UNSIGNED_INT b_abs = b < 0 ? - (T_UNSIGNED_INT) b : b;
T_UNSIGNED_INT min_abs = - (T_UNSIGNED_INT) T_INT_MIN;
T_UNSIGNED_INT max_abs = T_INT_MAX;
T_UNSIGNED_INT limit_pos = (0 <= a && 0 <= b) || (a < 0 && b < 0);
bool limit_pos = (0 <= a && 0 <= b) || (a < 0 && b < 0);
T_UNSIGNED_INT limit = limit_pos ? max_abs : min_abs;
T_UNSIGNED_INT max_b = a_abs / limit;
T_UNSIGNED_INT max_b = limit / a_abs;
return max_b < b_abs;
}
}