Menu

#4300 Tcl_AppendObjToObj cannot append obj to self

obsolete: 8.5.6
closed-fixed
5
2009-03-30
2009-02-15
Don Porter
No

This will crash:

Tcl_AppendObjToObj(objPtr, objPtr);

Same problem with

int numBytes;
char *bytes
= Tcl_GetStringFromObj(objPtr, &numBytes);
Tcl_AppendToObj(objPtr, bytes, numBytes);

and other equivalents.

Same problem with

int numChars;
Tcl_UniChar *unicode
= Tcl_GetUnicodeFromObj(objPtr, &numChars);
Tcl_AppendUnicodeToObj(objPtr, unicode, numChars);

The latest optimization for bytearray values
does work. That's the only case that does.
(Good work, dkf!)

Discussion

  • Donal K. Fellows

    I'd not expect the T_GSFO->T_ATO or T_GUFO->T_AUTO versions to work. There simply isn't quite enough information passed to Tcl's internals to be able to spot the sharing (if you think there is, consider the case where you're appending everything but the first character so a pointer equality test won't spot the issue...)

    However, T_AOTO should be able to cope: that's got precisely the right info to know when it has to be careful. (Or we can assume that expanding the buffers won't necessarily preserve the pointers to any character/unicode array, but will preserve the lengths, which is what I did. And that's why it won't work for the other cases.)

     
  • Don Porter

    Don Porter - 2009-02-16

    fixed in HEAD

     
  • Don Porter

    Don Porter - 2009-03-30
    • status: open --> closed-fixed
     
  • Don Porter

    Don Porter - 2009-03-30

    fix backported.