diff options
author | dgp <dgp@users.sourceforge.net> | 2016-06-22 17:38:31 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2016-06-22 17:38:31 (GMT) |
commit | f37d8b3d6914b1f9637faf57175429443591e0ef (patch) | |
tree | 26da6fd007068852b15837be7442bada8daaa633 /generic/tclUtil.c | |
parent | 4ca2f26fbcf054a93c71bb226f374e1b7d4fa698 (diff) | |
download | tcl-f37d8b3d6914b1f9637faf57175429443591e0ef.zip tcl-f37d8b3d6914b1f9637faf57175429443591e0ef.tar.gz tcl-f37d8b3d6914b1f9637faf57175429443591e0ef.tar.bz2 |
[16896d49fd] Tcl_DStrings should tolerate appends to self.
Diffstat (limited to 'generic/tclUtil.c')
-rw-r--r-- | generic/tclUtil.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c index bc1490e..34d4be2 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -2431,8 +2431,20 @@ Tcl_DStringAppend( memcpy(newString, dsPtr->string, (size_t) dsPtr->length); dsPtr->string = newString; } else { + int offset = -1; + + /* See [16896d49fd] */ + if (bytes >= dsPtr->string + && bytes <= dsPtr->string + dsPtr->length) { + offset = bytes - dsPtr->string; + } + dsPtr->string = ckrealloc((void *) dsPtr->string, (size_t) dsPtr->spaceAvl); + + if (offset >= 0) { + bytes = dsPtr->string + offset; + } } } @@ -2495,8 +2507,20 @@ Tcl_DStringAppendElement( memcpy(newString, dsPtr->string, (size_t) dsPtr->length); dsPtr->string = newString; } else { + int offset = -1; + + /* See [16896d49fd] */ + if (element >= dsPtr->string + && element <= dsPtr->string + dsPtr->length) { + offset = element - dsPtr->string; + } + dsPtr->string = (char *) ckrealloc((void *) dsPtr->string, (size_t) dsPtr->spaceAvl); + + if (offset >= 0) { + element = dsPtr->string + offset; + } } dst = dsPtr->string + dsPtr->length; } |