Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: ac2a39f0922d2e2f521afc5007bf943283319ecd5f8dd11a4f589ff4433914d4
Ticket: f894a85b9a4412d77d4f3234e5a244b7b4d476a2
Free-form clock scan silently wraps numbers that do not fit into an int (regression in 9.0)
User & Date: jan.nijtmans on 2026-11-14 10:22:35
Changes

  1. comment changed to:
    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`.
    
  2. icomment: "+1, just go ahead!"
  3. login: "jan.nijtmans"
  4. mimetype: "text/x-fossil-wiki"