Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2003-02-02
04:37 • Closed ticket [675356ffff]: clock clicks -milliseconds logic confused plus 7... artifact: 7bd6194135 user: kennykb
2003-01-27
18:14 • Ticket [675356ffff]: 4 changes artifact: ee37137e12 user: nobody
11:05 • New ticket [675356ffff]. artifact: 5505ad0136 user: nobody

clock clicks -milliseconds logic confused

Closed / Fixed675356ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 24 years ago
Descriptionplain2003-01-27 11:05:15
tclClock.c

88:    switch ((enum command) index) {
89:     case COMMAND_CLICKS:    {               /* clicks 
*/
90:         int forceMilli = 0;
91:
92:         if (objc == 3) {
93:             format = Tcl_GetStringFromObj(objv[2], 
&index);
94:             if (strncmp(format, "-milliseconds",
95:                     (unsigned int) index) == 0) {
96:                 forceMilli = 1;
97:             } else {
98:                 Tcl_AppendStringsToObj(resultPtr,
99:                         "bad switch \"", format,
100:                        "\": must be -milliseconds", (char *) 
NULL);
101:                return TCL_ERROR;
102:            }

The 'n' argument to strncmp should not be index (which 
happens to be 0), but presumably strlen("-milliseconds")
==13.
nobodyplain2003-01-27 18:14:01
Logged In: NO 

Also notice that "clock clicks -milliseconds"
is giving negative results:

% clock clicks -milli
-11350295

Is this correct behaviour or is this an int/long casting
issue?
kennykbplain2003-02-02 04:37:36
Logged In: YES 
user_id=99768

No bug here, except for the little bug that [clock clicks {}] 
and [clock clicks -] were being recognized as
[clock clicks -milliseconds].

The 'index' variable was being reused, and at the time of the
'strncmp' call, it's the string length of objv[2].  So the logic
is correct except for making sure that the string contains
at least two characters.

The negative value for milliseconds is also correct.  See
http://www.tcl.tk/cgi-bin/tct/tip/124.html
for a proposal to eliminate that issue.
Log in (anonymous is fine) to add a comment.