summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2016-06-22 18:05:46 (GMT)
committerdgp <dgp@users.sourceforge.net>2016-06-22 18:05:46 (GMT)
commitf26610cd68a05e3e665dcd0fb29fc8e20326fbfe (patch)
tree84ce9640fdc67662fd037080a5b99480d48cfc26 /generic
parent47593ffc5f6d722c616077fb304913de86953d8d (diff)
parenta584299193791f22e2e29fefceec030584feae54 (diff)
downloadtcl-f26610cd68a05e3e665dcd0fb29fc8e20326fbfe.zip
tcl-f26610cd68a05e3e665dcd0fb29fc8e20326fbfe.tar.gz
tcl-f26610cd68a05e3e665dcd0fb29fc8e20326fbfe.tar.bz2
[16896d49fd] Tcl_DStrings should tolerate appends to self.
Diffstat (limited to 'generic')
-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;
}