Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2024-08-24
11:01
Merge [93689150f7296074]: Fix [32b88975f7]: clock format returns spurious errors. check-in: a83271b2c6 user: pooryorick tags: unchained, INCOMPATIBLE_LICENSE
2023-11-20
20:55 • Closed ticket [32b88975f7]: clock format returns spurious errors plus 8 othe... artifact: 564667533d user: jan.nijtmans
20:45
Fix [32b88975f7]: clock format returns spurious errors check-in: af4b808872 user: jan.nijtmans tags: core-8-6-branch
13:56 • New ticket [32b88975f7] clock format returns spurious errors. artifact: 0cce8ed6a0 user: gahr

clock format returns spurious errors

Closed / Fixed32b88975f794c39d29308ec8bcd4aafd779f220aCreated 3 years agoUpdated 3 years ago
Descriptionwiki2023-11-20 13:56:06
In ConvertLocalToUTCUsingC, we use mktime then check errno without checking whether mktime returned an error, i.e., -1.

As nicely explained in this thread on the tz mailing list, doing so is an error.

As it turns out, in FreeBSD we use a version of tz's code that sets errno internally even on the success path. This results in [clock scan] erroring out even on valid input:

clock scan 2000-01-01T00:00:00 -timezone :localtime  -format %Y-%m-%dT%H:%M:%S
time value too large/small to represent

Here's the patch I suggest:

--- generic/tclClock.c.orig     2023-11-03 19:56:24.000000000 +0000
+++ generic/tclClock.c  2023-11-20 13:49:18.128631000 +0000
@@ -894,7 +894,7 @@
     Tcl_MutexLock(&clockMutex);
     errno = 0;
     fields->seconds = (Tcl_WideInt) mktime(&timeVal);
-    localErrno = errno;
+    localErrno = fields->seconds == -1 ? errno : 0;
     Tcl_MutexUnlock(&clockMutex);
 
     /*
Referenced by2
jan.nijtmanswiki2023-11-20 20:55:07

Fixed [here] (yes, that's 8.6) and up.

Thanks for the report and the patch!

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