| Ticket UUID: | 3363556 | ||
| Title: | Tcl_SetObjResult can't handle NULL, despite documentation | ||
| Type: | Bug | Created on: | 2011-07-11 23:09:47 |
| Submitter: | foomench | Assigned to: | msofer |
| Subsystem: | 10. Objects | Severity: | |
| Priority: | 5 Medium | Last modified: | 2011-07-12 21:07:41 |
| Status: | Open | Closed by: | |
| Resolution: | None | Closed on: | |
| Version: | None | ||
| Description: | ||||
Documentation for Tcl_SetObjResult states, "If objPtr is NULL, interp->objResult is set to a new Tcl object containing an empty string." However, the code doesn't do this. In fact, it tries to use objPtr in a Tcl_IncrRefCount call without checking for NULL, which results in an exception. Here's the code:
void
Tcl_SetObjResult(
Tcl_Interp *interp,/* Interpreter with which to associate the
* return object value. */
register Tcl_Obj *objPtr)/* Tcl object to be returned. If NULL, the obj
* result is made an empty string object. */
{
register Interp *iPtr = (Interp *) interp;
register Tcl_Obj *oldObjResult = iPtr->objResultPtr;
iPtr->objResultPtr = objPtr;
Tcl_IncrRefCount(objPtr);/* since interp result is a reference */
...
| ||||
| User Comments: | ||||
msofer added on 2011-07-12 19:52:02:
I could only find an inline comment (in the function argument list) stating that NULL is converted to empty, but it does not correspond exactly to your quote. That comment is indeed NOT in agreement with the code, one of the two should (and will) be fixed. I couldn't find any docs mentioning Tcl_SetObjResult's ability to handle a NULL objPtr. The manual page for Tcl_SetObjResult describes pretty much what the code is doing: "Tcl_SetObjResult arranges for objPtr to be the result for interp, replacing any existing result. The result is left pointing to the object referenced by objPtr. objPtr's reference count is incremented since there is now a new reference to it from interp. The reference count for any old result object is decremented and the old result object is freed if no references to it remain." This part of the man page SetResult.3 seems to have been unchanged since 1998-03-26 Which documentation are you quoting from? foomench added on 2011-07-12 20:21:58:
I saw the inline comment in current (8.5.10) code. My quote is from http://www.astro.princeton.edu/~rhl/Tcl-Tk_docs/tcl/SetObjResult.3.html which is apparently not current. Sorry about the duplicate--browser back button did that. msofer added on 2011-07-12 21:07:41:
Those docs are for tcl8.0a1 (first alpha version of Tcl8), very very much out of date and not even corresponding to any tcl version that was actually released. | ||||
