diff options
author | dgp <dgp@users.sourceforge.net> | 2018-11-13 21:10:33 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2018-11-13 21:10:33 (GMT) |
commit | 3e8ffff6a3663495e9cbc3fe5eb0dd1798904dbe (patch) | |
tree | ffc9422e6e57f2706528cb9e780a54717f2089a6 /generic/tclListObj.c | |
parent | ad8c23540cd977b9e923053d0e86a56207761680 (diff) | |
download | tcl-3e8ffff6a3663495e9cbc3fe5eb0dd1798904dbe.zip tcl-3e8ffff6a3663495e9cbc3fe5eb0dd1798904dbe.tar.gz tcl-3e8ffff6a3663495e9cbc3fe5eb0dd1798904dbe.tar.bz2 |
[35a8f1c04a] Fix bad lengths when creating string rep of some lists.
Diffstat (limited to 'generic/tclListObj.c')
-rw-r--r-- | generic/tclListObj.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/generic/tclListObj.c b/generic/tclListObj.c index d7f9aeb..a75c3d3 100644 --- a/generic/tclListObj.c +++ b/generic/tclListObj.c @@ -2110,7 +2110,7 @@ UpdateStringOfList( # define LOCAL_SIZE 64 char localFlags[LOCAL_SIZE], *flagPtr = NULL; int numElems, i, length, bytesNeeded = 0; - const char *elem; + const char *elem, *start; char *dst; Tcl_Obj **elemPtrs; List *listRepPtr; @@ -2169,7 +2169,7 @@ UpdateStringOfList( * Pass 2: copy into string rep buffer. */ - dst = Tcl_InitStringRep(listPtr, NULL, bytesNeeded); + start = dst = Tcl_InitStringRep(listPtr, NULL, bytesNeeded); TclOOM(dst, bytesNeeded); for (i = 0; i < numElems; i++) { flagPtr[i] |= (i ? TCL_DONT_QUOTE_HASH : 0); @@ -2177,7 +2177,9 @@ UpdateStringOfList( dst += TclConvertElement(elem, length, dst, flagPtr[i]); *dst++ = ' '; } - (void) Tcl_InitStringRep(listPtr, NULL, bytesNeeded); + + /* Set the string length to what was actually written, the safe choice */ + (void) Tcl_InitStringRep(listPtr, NULL, dst - 1 - start); if (flagPtr != localFlags) { Tcl_Free(flagPtr); |