signed integer overflow in Tcl_SetBignumObj()
Closed / Fixed1c60dca3412236a4992ff57dae575a7df91b65f0Created 5 years agoUpdated 5 years ago
Descriptionwiki2022-02-16 00:15:17
UBSan (-fsanitize=signed-integer-overflow) errors for 32-bit long and 64-bit long long:
% set a -0x8000000000000001; incr a 1 tcl/generic/tclObj.c:3576:6: runtime error: negation of -9223372036854775808 cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself -9223372036854775808 % set b -0x8000000000000001; incr b 0x7fffffff80000001 tcl/generic/tclObj.c:3550:6: runtime error: negation of -2147483648 cannot be represented in type 'long int'; cast to an unsigned type to negate this value to itself -2147483648
As with [89de498973], this can be avoided by negating before casting, and by subtracting from 0 (binary minus) to avoid compiler warnings for unary minus with unsigned operand (e.g. MSVC /W2 warning C4146). See attached patch.
Referenced by1
414608568aFix [1c60dca341]: signed integer overflow in Tcl_SetBignumObj() check-in2022-02-16 16:10:22
jan.nijtmanswiki2022-02-16 16:12:12
Fixed[here]
Thanks for the report!
Log in (anonymous is fine) to add a comment.