summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2016-06-22 18:04:23 (GMT)
committerdgp <dgp@users.sourceforge.net>2016-06-22 18:04:23 (GMT)
commita584299193791f22e2e29fefceec030584feae54 (patch)
treebc89748f2bf84c0a4c6c5500cceb8bf9feaff35e
parentfa0cec87e3c5670b11c89aef1aba30201a22ea43 (diff)
parentf37d8b3d6914b1f9637faf57175429443591e0ef (diff)
downloadtcl-a584299193791f22e2e29fefceec030584feae54.zip
tcl-a584299193791f22e2e29fefceec030584feae54.tar.gz
tcl-a584299193791f22e2e29fefceec030584feae54.tar.bz2
[16896d49fd] Tcl_DStrings should tolerate appends to self.
-rw-r--r--generic/tclUtil.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 2b0fb72..553593c 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -2634,7 +2634,19 @@ 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(dsPtr->string, dsPtr->spaceAvl);
+
+ if (offset >= 0) {
+ bytes = dsPtr->string + offset;
+ }
}
}
@@ -2725,7 +2737,19 @@ 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 = ckrealloc(dsPtr->string, dsPtr->spaceAvl);
+
+ if (offset >= 0) {
+ element = dsPtr->string + offset;
+ }
}
dst = dsPtr->string + dsPtr->length;
}