Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2022-02-16
16:12 • Closed ticket [1c60dca341]: signed integer overflow in Tcl_SetBignumObj() pl... artifact: 0042dbc24d user: jan.nijtmans
16:10
Fix [1c60dca341]: signed integer overflow in Tcl_SetBignumObj() check-in: 414608568a user: jan.nijtmans tags: core-8-6-branch
00:15 • Add attachment setbignumobj-sif.diff to ticket [1c60dca3412236a4|1c60dc... artifact: 769cb802b5 user: chrstphrchvz
00:15 • New ticket [1c60dca341] signed integer overflow in Tcl_SetBignumObj(). artifact: a7be3a81ab user: chrstphrchvz

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
jan.nijtmanswiki2022-02-16 16:12:12

Fixed[here]

Thanks for the report!

Log in (anonymous is fine) to add a comment.