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.