Signed integer overflow in Clock_str2wideInt()
UBSan -fsanitize=signed-integer-overflow errors as encountered during these tests:
clock-6.9:
generic/tclClockFmt.c:192:21: runtime error: signed integer overflow: -9223372036854775800 - 9 cannot be represented in type 'Tcl_WideInt' (aka 'long long')clock-6.10:
generic/tclClockFmt.c:182:21: runtime error: signed integer overflow: 9223372036854775800 + 8 cannot be represented in type 'Tcl_WideInt' (aka 'long long')clock-6.10a:
generic/tclClockFmt.c:182:16: runtime error: signed integer overflow: 2767011611056432742 * 10 cannot be represented in type 'Tcl_WideInt' (aka 'long long')clock-6.10a-:
generic/tclClockFmt.c:192:16: runtime error: signed integer overflow: -2767011611056432742 * 10 cannot be represented in type 'Tcl_WideInt' (aka 'long long')
But maybe this is won't-fix, given the usage of # pragma GCC optimize("no-trapv").
This is not directly won't-fix, but the overflow is indeed covered below by check whether original is smaller/larger (depending on sign) than result after operation. We can surely rewrite it more strict to pass the sanitizer.
I’d like to help make this UBSan-clean. Based on sebres’ note, it seems the current logic is fine but UBSan is flagging intermediate signed overflow. Do you have a preferred direction for addressing this — e.g., restructuring the arithmetic to avoid overflow in signed space (pre-checks / bounds checks), or another approach you consider idiomatic here? If you’re OK with it, I can draft a patch and validate it with UBSan, focusing on the reported tests (clock-6.9/6.10/6.10a).
I too would prefer these to be fixed even if benign just to avoid clutter and missing real warnings.
Shall be fixed in all branches (based on new clock-engine), starting from [f954da0082db5ac1], thus close now.