Tcl Source Code

View Ticket
Login
Ticket UUID: af3ebc5fafe0097cb93f0304cd4b7676831a706e
Title: clock scan and clock add bugs in error cases / with abbreviated options
Type: Bug Created on: 2023-05-22 11:57:25
Submitter: pointsman Assigned to: nobody
Subsystem: 16. Commands A-H Severity: Minor
Priority: 5 Medium Last modified: 2023-06-05 09:51:01
Status: Closed Closed by: pointsman
Resolution: Fixed Closed on: 2023-06-05 09:51:01
Version: 8.6 - 9.0
Description:
The clock command - as the other core commands - supports abbreviated options. Due to deficiencies in the Tcl code in library/clock.tcl this does not work as expected in some error cases.

Example

clock scan 1970-01-01 -format %Y-%m-%d -gmt true -timezone :Europe/Berlin

==> cannot use -gmt and -timezone in same call

as the documentation say and is expected. Though

clock scan 1970-01-01 -format %Y-%m-%d -g true -timezone :Europe/Berlin

==> 0

returns a result without error.

Looking at 
[https://core.tcl-lang.org/tcl/file?udc=1&ln=1209-1242&ci=586f490293ce298c&name=library%2Fclock.tcl] (thats from core-8-6-branch, any later up to trunk has the same code) it is pretty clear what happens. In the foreach loop the option as given (even in abbreviated form) is used as key but the tests later on test only for the full option name.

Other examples of erroneous option processing than the example above can easily found with this observation.

With the clock add command it is even a bit worser. Look at

[https://core.tcl-lang.org/tcl/file?udc=1&ln=4240-4288&ci=586f490293ce298c&name=library%2Fclock.tcl]

In the part following the comment "# Check options for validity" the existence of saw(-gmt) and saw(-timezone) is tested but the saw array isn't set in any case by the code above - the test will never fire.
User Comments:
pointsman added on 2023-05-22 12:19:23:
Proposed fix at [827cc031bc4]. If nobody objects I'll merge in a few days.

oehhar added on 2023-05-22 15:04:45:

Just a remark. I saw today a ticket by Mr AndroWish:

https://core.tcl-lang.org/tdbcsqlite3/info/d9fe8c58e03eacc1

An utility function of TCL is used to do the whole argument magic. May this be a possibility to fix this to ?

I am always surprised, how many bugs are included in this abreviated command feature...

Thank you and take care, Harald


pointsman added on 2023-05-22 21:10:45:
Surely the option handling could be rewritten by using tcl::prefix. But the problem here is that some option combination are not allowed and that tests did not work. The least invasive seemd to me to change the code just a bit so that it does what obviously was intended.

This is just a minor fix for otherwise working code. Rewriting the code has just the risk of new oversights without additional benefit.

If clock can get some love then this is perhaps better spend otherwise.

oehhar added on 2023-05-23 07:28:14:

Ok, thank you for the clarification, I appreciate, Harald


jan.nijtmans added on 2023-06-02 22:23:24:

LGTM. Thanks!


pointsman added on 2023-06-05 09:51:01:
Fix merged by Jan with [72f78b6085]. I slightly corrected the fix with [aaecc4619].

@Jan not a big thing, you perhaps thought I forgot about this but if you merged and closed the branch why did you left it to me to close the ticket?

And what are this (apparently) white-space changes, messing up the simple fix as shown by [72f78b60851aaf8d]? I can't see this white-space only changes shown by the web interface with a diff between the two check-outs [72f78b6085] and [dba07ed3df].. Is the problem the web-interface, me or something else?