#4807 Incorrect Tcl Interpreter Obj Result

obsolete: 8.5.9
closed-fixed
5
2011-03-08
2011-03-08
No

There is a problem with obj results returned from an
interpreter. When the obj result is reset, a tclStringType
internal rep can be left for an empty string. This then
gives inconsistent results for a new obj result.

The attached example program objresult_example.c
demonstrates the issue.

The problem is in ResetObjResult in tclResult.c, where it is
assumed that the obj result only needs to be reset if it is
not an empty string. Changing this so that is always clears
any internal rep fixes the problem.

This patch is against the 8.5.9 release:

*** tclResult.c.859 Wed Mar 24 15:31:48 2010
--- tclResult.c Tue Mar 8 11:21:20 2011
***************
*** 961,972 ****
TclNewObj(objResultPtr);
Tcl_IncrRefCount(objResultPtr);
iPtr->objResultPtr = objResultPtr;
! } else if (objResultPtr->bytes != tclEmptyStringRep) {
! if (objResultPtr->bytes != NULL) {
! ckfree((char *) objResultPtr->bytes);
}
- objResultPtr->bytes = tclEmptyStringRep;
- objResultPtr->length = 0;
TclFreeIntRep(objResultPtr);
objResultPtr->typePtr = NULL;
}
--- 961,974 ----
TclNewObj(objResultPtr);
Tcl_IncrRefCount(objResultPtr);
iPtr->objResultPtr = objResultPtr;
! } else {
! if (objResultPtr->bytes != tclEmptyStringRep) {
! if (objResultPtr->bytes != NULL) {
! ckfree((char *) objResultPtr->bytes);
! }
! objResultPtr->bytes = tclEmptyStringRep;
! objResultPtr->length = 0;
}
TclFreeIntRep(objResultPtr);
objResultPtr->typePtr = NULL;
}

Discussion

  • miguel sofer

    miguel sofer - 2011-03-08
    • assigned_to: msofer --> dgp
     
  • Don Porter

    Don Porter - 2011-03-08

    Bug introduced in checkin a9ae49ef27 2007-11-10

    Bad miguel!

     
  • Don Porter

    Don Porter - 2011-03-08
    • assigned_to: dgp --> msofer
     
  • Don Porter

    Don Porter - 2011-03-08

    fixed in all open branches.

     
  • Don Porter

    Don Porter - 2011-03-08
    • assigned_to: msofer --> dgp
    • status: open --> closed-fixed