Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Signed integer overflow in Clock_str2wideInt()

Closed / Fixed96e5c814eb9ed95591ce30904943025c35673a96Created 1 year agoUpdated 319 days ago
Descriptionmarkdown2025-09-20 18:27:44

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").

sebreswiki2025-12-29 20:39:15

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.

cduboisplain2026-01-06 03:56:16
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).
apnadkarniplain2026-01-06 06:09:42
I too would prefer these to be fixed even if benign just to avoid clutter and missing real warnings.
sebreswiki2026-01-18 02:00:11

Shall be fixed in all branches (based on new clock-engine), starting from [f954da0082db5ac1], thus close now.

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