Repository navigation
lib: range-check doubles before auto-converting to int and int64 - #309
Conversation
|
|
||
| static int __config_double_fits_int(double value) | ||
| { | ||
| return((value >= -2147483648.0) && (value < 2147483648.0)); |
There was a problem hiding this comment.
Instead of hardcoded constant 2147483648.0, why not (double)INT_MAX + 1.0
Similarly for the other constants.
There was a problem hiding this comment.
done, the int bounds are (double)INT_MIN and (double)INT_MAX + 1.0 now. for the int64 upper bound i used -(double)LLONG_MIN instead of (double)LLONG_MAX + 1.0: LLONG_MAX already rounds up to 2^63 as a double, so the + 1.0 is a no-op there, and on x87 with excess precision the sum can come out as 2^63 + 1, which would let 2^63 itself through the check. can switch it to the symmetric form if you prefer.
|
please rebase and then I'll merge. |
03774f4 to
bf0d2c0
Compare
|
rebased on master. the only conflict was tests/tests.c, where WriteLargeFloat from #307 landed in the same spot, so both tests are kept now and the suite passes. |
with autoconvert on,
__config_setting_get_int(),__config_setting_get_int64()andconfig_setting_set_float()cast a double straight to int or long long, so a config value likex = 1e300;read throughconfig_lookup_int()is undefined behavior (ubsan:1e+300 is outside the range of representable values of type 'int') and the lookup reports success with a saturated or indefinite value; they now check the double fits the target type first and return CONFIG_FALSE otherwise, the same way the int64-to-int path already does, and the newAutoConvertFloatToIntegertest fails without the fix.