|
2026-11-24
| ||
| 17:44 | • Closed ticket [f894a85b9a]: Free-form clock scan silently wraps numbers that do ... artifact: 3f628278dc user: serhiy.storchaka | |
| 11:34 | Fix [f894a85b9a]: Free-form clock scan silently wraps numbers that do not fit into an int check-in: a0288fe887 user: jan.nijtmans tags: core-8-6-branch | |
|
2026-11-14
| ||
| 13:45 | • Ticket [f894a85b9a] Free-form clock scan silently wraps numbers that do not fit ... artifact: 441e0b7403 user: serhiy.storchaka | |
| 13:10 | Fix relative months and years before the common era, and dates that wrap around in clock add and the... closed check-in: 60c16ebe54 user: serhiy.storchaka tags: clock-range-8-6 | |
| 12:25 | Fix [f894a85b9a]: Free-form clock scan silently wraps numbers that do not fit into an int (regressio... check-in: df2b525fbd user: serhiy.storchaka tags: core-9-0-branch | |
| 12:23 | Fix [f894a85b9a]: Free-form clock scan silently wraps numbers that do not fit into an int (regressio... check-in: 21bc2b48f7 user: serhiy.storchaka tags: trunk, main | |
| 10:22 | • Ticket [f894a85b9a] Free-form clock scan silently wraps numbers that do not fit ... artifact: ac2a39f092 user: jan.nijtmans | |
| 09:29 | • Ticket [f894a85b9a]: 3 changes artifact: 93a795aab6 user: serhiy.storchaka | |
| 09:28 | Fix [f894a85b9a]: free-form clock scan silently wraps numbers that do not fit into an int. Numbers ... closed check-in: 018bd8d323 user: serhiy.storchaka tags: clock-freescan-int-range | |
| 08:37 | • Ticket [8afd93d3d3] Clock format fails on NetBSD 11.1 on Sparc64 status stil... artifact: 84043d1988 user: serhiy.storchaka | |
| 08:05 | • New ticket [f894a85b9a] Free-form clock scan silently wraps numbers that do not ... artifact: 9fcc566164 user: serhiy.storchaka | |
Free-form clock scan silently wraps numbers that do not fit into an int (regression in 9.0)
Since the clock rewrite in Tcl 9.0 (TIP 688), the free-form parser of clock scan reads numbers as 64-bit integers, but stores them into the int fields of the date (hour, minutes, day, month, year, day ordinal). A number that does not fit into an int is truncated, and the result is often a valid value, so a wrong date is returned without error:
| Input | 9.0.5 and 9.1.1 | 8.6.18 |
|---|---|---|
clock scan 12:4294967301:00 |
12:05:00 | syntax error |
clock scan 4294967308:00:00 |
12:00:00 | syntax error |
clock scan 4294967297/02/2026 |
2026-01-02 | syntax error |
clock scan 02/4294967297/2026 |
2026-02-01 | syntax error |
clock scan 02/03/4294969322 |
2026-02-03 | syntax error |
clock scan "-4294967297 Monday" |
1969-12-29 (a Monday) | syntax error |
With Jan's fix for [8afd93d3d3], which makes secondOfMin an int, the seconds field would be affected too: 12:00:4294967301 would give 12:00:05.
The year is the only field whose valid range (-min-year/-max-year) is the whole int range by default, so clamping alone cannot reject it.
Relative months and years are wrapped too (with -base 0 -gmt 1):
| Input | 9.0.5 and 9.1.1 |
|---|---|
clock scan "4294967297 months" |
1970-02-01 (1 month) |
clock scan "4294967297 years" |
1971-01-01 (1 year) |
clock scan "next 4294967297 Feb" |
1970-02-01 |
Relative days, weeks, fortnights and seconds are 64-bit and give the right result. 8.6.18 gives wrong results for all relative units with this number (the year 429502 for each of them) and a syntax error for next 4294967297 Feb.
a0288fe887Fix [f894a85b9a]: Free-form clock scan silently wraps numbers that do not fit into an int check-in2026-11-24 11:34:4360c16ebe54Fix relative months and years before the common era, and dates that wrap around in clock add and the julian day helpers (see [f894a85b9a]). AddMonths added the months to the year of the era, so 1 year after 101 B.C.E. gave 102 B.C.E. It now works with the astronomical year. The julian day was an int, and TclGetIntFromObj() accepts values up to UINT_MAX and wraps them around, so clock add with large offsets and the julian day helpers returned wrapped dates. The julian day is now a Tcl_WideInt, the helpers calculate in 64 bits, and julian days out of +-0x7F000000 (about 5.8 million years) raise "integer value too large to represent". clock format of such seconds is unchanged (clock-61.3). check-in2026-11-14 13:10:44df2b525fbdFix [f894a85b9a]: Free-form clock scan silently wraps numbers that do not fit into an int (regression in 9.0) check-in2026-11-14 12:25:2421bc2b48f7Fix [f894a85b9a]: Free-form clock scan silently wraps numbers that do not fit into an int (regression in 9.0) check-in2026-11-14 12:23:45018bd8d323Fix [f894a85b9a]: free-form clock scan silently wraps numbers that do not fit into an int. Numbers that do not fit into an int are no longer truncated to a value that may be valid. The year is kept as a Tcl_WideInt by the parser and checked, and relative months, years, days, seconds, "next N Month" and "N Monday" are calculated in 64 bits. Also fix relative months and years before the common era, which went in the wrong direction, signed integer overflows with -valid 0 and in the julian day helpers, and overflows in clock add with large offsets. clock add now raises "integer value too large to represent" for a result outside the range of clock seconds. check-in2026-11-14 09:28:5184043d1988Ticket [8afd93d3d3] Clock format fails on NetBSD 11.1 on Sparc64 status still Open with 3 other changes ticket2026-11-14 08:37:21
Proposed fix in branch clock-freescan-int-range. Numbers that do not fit into an int are rejected instead of truncated, and relative counts are calculated in 64 bits. The branch also fixes the following bugs.
Relative months and years before the common era go in the wrong direction (base 101-03-15 B.C.E., -gmt 1):
| Input | 8.6.18 and 9.0 | Branch |
|---|---|---|
clock scan "1 year" |
102-03-15 B.C.E. | 100-03-15 B.C.E. |
clock scan "13 months" |
102-04-15 B.C.E. | 100-04-15 B.C.E. |
clock scan "next Feb" |
102-02-15 B.C.E. | 100-02-15 B.C.E. |
clock add $base 1 year |
102-03-15 B.C.E. | 100-03-15 B.C.E. |
Signed integer overflows with -valid 0 (-base 0 -gmt 1). The overflow is undefined behaviour; the 9.0 values are what gcc gives:
| Input | 9.0 | Branch |
|---|---|---|
Dec 31 2147483647 (time 21474836:47) |
31450692 | 77340862020 |
02/2147483647/2026 |
-185540816332800 | 185544356918400 |
14/02/2147483647 |
67675204942704000 | 67767976236297600 |
Overflows in clock add (-gmt 1):
| Input | 9.0 | Branch |
|---|---|---|
clock add 0 67553994410557440 hours |
3386706919782612992 | integer value too large to represent |
clock add 0 2147483647 weekdays |
-111325552329600 | 259759622044800 |
clock add 0 2147483647 years |
-31536000 | integer value too large to represent |
clock add now raises "integer value too large to represent" for a result outside the range of clock seconds, as it already does for such a base. Before, clock add 0 67553994410557440 seconds 67553994410557440 seconds returned 135107988821114880, which clock format does not accept.
+1, just go ahead!
For 8.6: proposed fix in branch clock-range-8-6. 8.6 has the B.C.E. bug in relative months and years, and wraps dates in clock add and the julian day helpers (clock add 0 2147483647 years gave 4455773-12-22 instead of the year 2147485617). Julian days beyond about ±5.8 million years now raise "integer value too large to represent". Numbers that do not fit into an int are already a syntax error in the 8.6 parser, and clock format of such seconds is unchanged.
Merged into core-8-6-branch by Jan in [a0288fe887]. With [21bc2b48f7] (main) and [df2b525fbd] (core-9-0-branch), the fix is in all three branches.