Artifacts Associated With Ticket 219082
Ticket change [fc5dded1d4] (rid 108226) by nobody on 2000-10-26 01:10:25:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
OriginalBugID: 5153 Bug Version: 8.3 SubmitDate: '2000-04-18' LastModified: '2000-06-03' Severity: SER Status: Released Submitter: techsupp ChangedBy: hobbs OS: Linux FixedDate: '2000-06-03' FixedInVersion: 8.4a1 ClosedDate: '2000-10-25' Name: Eric Perkins CVS: RCS: @(#) $Id: tclIndexObj.c,v 1.4 1999/06/28 23:49:31 redman Exp $ CustomShell: none Comments: the patch works as far as i've tested it. ReproducibleScript: //The following command is created in the interpreter and called with the syntax: // "mycommand key2" int mycommand(ClientData, Tcl_Interp * interp, int objc, Tcl_Obj * const objv[]) { typedef struct {char * key; ClientData d1; ClientData d2} MyStruct; MyStruct table[] = { {"key1",1,2}, {"key2",3,4}, {"key3",5,6} }; int index; int rv = Tcl_GetIndexFromObjStruct(interp,objv[1],(char**)table,sizeof(MyStruct),"option",0,&index); Tcl_WrongNumArgs(interp,2,obvj," rest of args"); return TCL_OK; } ObservedBehavior: segv during Tcl_WrongNumArgs The reason: the of the object for the first argument gets set to &table[0].key as it should, but the internalRep.twoPtrValue.ptr2 gets set to 1 (the number ofsets away from the beginning) when the string is retrieved from the table in Tcl_WrongNumArgs, the following expression is used: tablePtr[(int) objv[i]->internalRep.twoPtrValue.ptr2] which evaluates to ((char **)table)[1] which is, of course table[0].d1 and not table[1].key the internalRep.twoPtrValue.ptr2 should instead get set to (index * offset/sizeof(char*)), in this case, index*3 = 3. which evaluates correctly as ((char**)table)[3] = table[1].key DesiredBehavior: see above Patch: *** /home/edp/p1-edp/in/tcl8.3.0/generic/tclIndexObj.c Mon Jun 28 19:49:31 1999 --- tclIndexObj.c Tue Apr 18 14:59:59 2000 *************** *** 213,219 **** objPtr->typePtr->freeIntRepProc(objPtr); } objPtr->internalRep.twoPtrValue.ptr1 = (VOID *) tablePtr; ! objPtr->internalRep.twoPtrValue.ptr2 = (VOID *) index; objPtr->typePtr = &tclIndexType; *indexPtr = index; return TCL_OK; --- 213,219 ---- objPtr->typePtr->freeIntRepProc(objPtr); } objPtr->internalRep.twoPtrValue.ptr1 = (VOID *) tablePtr; ! objPtr->internalRep.twoPtrValue.ptr2 = (VOID *) (index*offset/sizeof(char*)); objPtr->typePtr = &tclIndexType; *indexPtr = index; return TCL_OK; PatchFiles: tclIndexObj.c Verified and patched for 8.4a1. -- 06/03/2000 hobbs - foundin initialized to: "obsolete: 8.3"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "nobody"
- subsystem initialized to: "69. Other"
- title initialized to:
Simple conceptual error in code for Tcl_GetIndexFromObjStruc
- type initialized to: "Bug"
Ticket change [3cbfecc044] (rid 120962) by welch on 2000-10-26 08:34:55:
- closedate changed to: "2000-10-26T01:34:55"
- closer changed to: "welch"
- priority changed to: "2"
- resolution changed to: "Fixed"
- status changed to: "Open"
Ticket change [d8c39b9a4e] (rid 107501) by sheltond on 2000-11-24 16:43:51:
- icomment:
Unfortunately, this fix breaks the code which returns the cached value from a previous lookup using the same object. The code at the top of Tcl_GetIndexFromObjStruct simply returns the value from the ptr2 field of the structure. Due to the change above, this now contains (in the above example) 3. In fact, the value which should be returned is 1. >if ((objPtr->typePtr == &tclIndexType) && > (objPtr->internalRep.twoPtrValue.ptr1 > == (VOID *) tablePtr)) { >*indexPtr = (int)objPtr->internalRep.twoPtrValue.ptr2; >return TCL_OK; >} I would suggest a fix along the lines of this (sorry about the abysmal formatting here, the input box it too small to see what one is doing): >if ((objPtr->typePtr == &tclIndexType) && > (objPtr->internalRep.twoPtrValue.ptr1 > == (VOID *) tablePtr)) { >*indexPtr = (int)objPtr->internalRep.twoPtrValue.ptr2 / > (offset/sizeof(char*)); >return TCL_OK; >} This will cause the cached value to be returned correctly. - login: "sheltond"
- mimetype: "text/plain"
- username: "sheltond"
- icomment:
Ticket change [06bb7641f9] (rid 89262) by sheltond on 2000-11-24 16:52:01:
- icomment:
BTW, I am working with version 8.3.2, though the same problem appears to be in the head of CVS.
- login: "sheltond"
- mimetype: "text/plain"
- username: "sheltond"
- icomment:
Ticket change [c51706599c] (rid 111937) by dkf on 2000-11-24 17:27:45:
- assignee changed to: "dkf"
- icomment:
Reopened.
- login: "dkf"
- mimetype: "text/plain"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Closed"
- subsystem changed to: "10. Objects"
- username: "dkf"
Ticket change [3f06a7fe8f] (rid 121379) by dkf on 2000-11-24 18:06:25:
- icomment:
OK, I've got a test that detects the original bug and the fault with the first fix. I'll check that, plus a fix that will work more universally, into CVS shortly
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [d5a7c9fade] (rid 123660) by dkf on 2000-11-24 18:28:07:
- closedate changed to: "2000-11-24T11:28:07"
- closer changed to: "dkf"
- resolution changed to: "Fixed"
- status changed to: "Closed"