Skip to content
Tcl Source Code History Of Ticket 219082
Login

History Of Ticket 219082

Artifacts Associated With Ticket 219082

  1. Ticket change [fc5dded1d4] (rid 108226) by nobody on 2000-10-26 01:10:25:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. 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
      
    4. foundin initialized to: "obsolete: 8.3"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "69. Other"
    10. title initialized to:
      Simple conceptual error in code for Tcl_GetIndexFromObjStruc
      
    11. type initialized to: "Bug"
  2. Ticket change [3cbfecc044] (rid 120962) by welch on 2000-10-26 08:34:55:

    1. closedate changed to: "2000-10-26T01:34:55"
    2. closer changed to: "welch"
    3. priority changed to: "2"
    4. resolution changed to: "Fixed"
    5. status changed to: "Open"
  3. Ticket change [d8c39b9a4e] (rid 107501) by sheltond on 2000-11-24 16:43:51:

    1. 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.
      
      
      
    2. login: "sheltond"
    3. mimetype: "text/plain"
    4. username: "sheltond"
  4. Ticket change [06bb7641f9] (rid 89262) by sheltond on 2000-11-24 16:52:01:

    1. icomment:
      BTW, I am working with version 8.3.2, though the same problem appears to be in the head of CVS.
      
      
    2. login: "sheltond"
    3. mimetype: "text/plain"
    4. username: "sheltond"
  5. Ticket change [c51706599c] (rid 111937) by dkf on 2000-11-24 17:27:45:

    1. assignee changed to: "dkf"
    2. icomment:
      Reopened.
      
      
    3. login: "dkf"
    4. mimetype: "text/plain"
    5. priority changed to: "5 Medium"
    6. resolution changed to: "None"
    7. status changed to: "Closed"
    8. subsystem changed to: "10. Objects"
    9. username: "dkf"
  6. Ticket change [3f06a7fe8f] (rid 121379) by dkf on 2000-11-24 18:06:25:

    1. 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
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  7. Ticket change [d5a7c9fade] (rid 123660) by dkf on 2000-11-24 18:28:07:

    1. closedate changed to: "2000-11-24T11:28:07"
    2. closer changed to: "dkf"
    3. resolution changed to: "Fixed"
    4. status changed to: "Closed"