Overview
| Artifact ID: | 84097736cad43723ccae895ec5b2702aa44e7de7115be38ada46a09c7b7834ca |
|---|---|
| Ticket: | 7bad415e3ec8baf40d087374000fbcbab511689c
Free-form clock scan reads "+02" as two minutes in 8.6 (backport of [51aa53616067cb63] without semantic predicates); the 9.x fix misreads a zone followed by a number |
| User & Date: | kenneth.kienle on 2026-09-08 05:59:54 |
Changes
- icomment:
Sergey, You are right about the ordering. The zone-first cases are now in their own test, clock-59.5. If you decide free-form scan should not accept a zone before the time, delete that one test and nothing else changes. That test is the only coverage of the tISOBASE half of the lookahead check. I measured this - remove the tISOBASE clause and clock-59.5 is the only test that fails. So if the zone-first order goes, that clause can go with it. How this came up: I build and test Tcl 8.6 against the system's tzdata rather than the bundled copy. Running the 8.6 suite in that configuration is what surfaced it. The main bug is the trailing form: clock scan {2023-11-15 00:13:20 +02} -gmt 1 Stock 8.6.18 returns 1700007080. The correct value is 1700000000. A signed zone is read as hhmm whatever its length, so "+02" becomes two minutes. That is how the system zoneinfo writes the %Z abbreviation, so clock format output does not survive a round trip through clock scan (Tcl's bundled tzdata writes "+0200" for %Z, which is why clock-59.2 passes today. %z is always four digits and is never affected). The clearest demonstration is to build 8.6 without bundled tzdata and run clock.test. Stock fails clock-59.2, and with this branch it passes. On a system whose zoneinfo also lacks CET, US/Eastern and US/East-Indiana you will see clock-30.33, 30.34, 39.1 and 44.1 fail as well, in stock and in the branch alike. Those are missing-zone errors from the tzdata install rather than anything to do with this bug, and I should not have listed them alongside 59.2. The branch is bug-7bad415e3e-8.6. It uses no semantic predicate, because your comment on [51aa53616067cb63] raised the older-bison question. The existing "sign tUNUMBER" action decides hours or hhmm itself. When the parser holds a numeric lookahead, it reads the digit count recorded before that lookahead. tclDate.c was regenerated with bison 3.8.2 by gendate. 14 shift/reduce conflicts, the same as stock. The branch also initialises the two digit-count fields in TclClockOldscanObjCmd. That function sets every other `yy*` field before yyparse but not yyDigitCount, and "number: tUNUMBER" reads it at the "yyDigitCount <= 2" test, which is a path "last" reaches because LookupWord returns it as tUNUMBER without passing the digit scanner. So stock reads an uninitialised stack value there. The read is real and I can move it, but only from C. Seeding yyDigitCount with 3 or more before the parse changes clock scan {last} -base 1700000000 -gmt 1 from 1699916400 to 1699919940. Seeding yyPrevDigitCount alone changes nothing: the keyword path assigns that field and never assigns yyDigitCount, which is the one "number: tUNUMBER" reads. What I could not do is reach it from a script - stock as shipped gives 1699916400, and so does stock after a preceding clock scan of {1234}, {20231115 001320}, {12} or {1130}, because the stack slot does not carry over. Because of that, I have written no test. Without editing the C there is no build on which one would discriminate, so it would pass either way and be a false control. One behaviour change from the lookahead work itself: clock scan {+last} -base 1700000000 -gmt 1 stock 1700000060 this branch 1700003600 9.0.5 1700003600 That one is not the initialisation, removing those two lines leaves it at 1700003600. The guard is yyDigitCount <= 2, so every negative value behaves exactly like 0, and I could not produce a build where the removal alone was visible, including one compiled with -ftrivial-auto-var-init=pattern, which changes nothing because the fill is negative as an int (0xFEFEFEFE under gcc, 0xAAAAAAAA under clang). Seeding the field with 3 or more does give stock's 1700000060. The read is real, and it is undefined behaviour either way. The removal is quiet because of what the caller's stack and the compiler happen to leave, not because the lines do nothing. With the lines removed the slot arrives as 0 on plain -O2 and as 0xFEFEFEFE under the pattern flag, both on the <= 2 side. The branch as submitted initialises the field and returns 1700003600 for that reason rather than by luck, which is the argument for keeping those two lines. Two measurements on 9.0.5, in case they are useful to you: clock scan {2023-11-15 00:13:20 +02} -gmt 1 -> 1700000000 correct clock scan {2023-11-15 00:13:20 +02 2024} -gmt 1 -> 1731629480 7080 s off The second should differ from the first only in the year. This branch gives 1731622400, which is what glibc gives for the same instant written as a date it accepts: date -u -d '2024-11-15 00:13:20 +02' +%s. So 8.6 with this change and 9.0.5 disagree on a zone followed by a number. I think 9.x is the one to correct, I just didn't want the difference to be a surprise. My first version of this patch had the same kind of bug I am describing in 9.x: "last" is returned as tUNUMBER by LookupWord without passing the digit scanner, so "clock scan {+0200 last month}" regressed against stock. That is fixed and clock-59.6 pins it. A later check found that my ISO-base test no longer covered the clause it was written for, because I had changed it to a four-digit zone. That is fixed too. Both errors were mine. There are three related pre-existing issues I did not touch, I'm happy to file them separately if that is useful. I checked each against 9.0.5. - "number: tUNUMBER" reads yyDigitCount with the same lookahead problem. clock scan {1130 15 Nov 2023} -gmt 1 gives 1704074400 in stock 8.6, where GNU date gives 1700047800. 9.0.5 raises an error on that input rather than answering it. - the non-J "n" day-of-year form is one day out. DeterminePosixDSTTime puts the 0-based n into the 1-based dayOfYear field. This one is in 9.0.5: with EST5EDT,59,300 in 2032, glibc starts DST on 29 February and 9.0.5 on the 28th, and n=58 and n=60 are a day early there as well. - `<zone> tomorrow` parses through a different rule and is an issue on stock. 9.0.5 is correct, {+0200 tomorrow} and {tomorrow +0200} both give 1699999200 there, where stock 8.6 gives 1717200000 and 1699999200. Kenneth - login: "kenneth.kienle"
- mimetype: "text/x-markdown"