summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2018-03-20 16:10:49 (GMT)
committerdgp <dgp@users.sourceforge.net>2018-03-20 16:10:49 (GMT)
commitbac2aebf1061014fdf5973b4d8d79544d24e74e0 (patch)
tree28c294bddda994e96d4f236e556800b430e35c20
parentdf06afadcfb949909d6a640b77fe234e266dc848 (diff)
downloadtcl-bac2aebf1061014fdf5973b4d8d79544d24e74e0.zip
tcl-bac2aebf1061014fdf5973b4d8d79544d24e74e0.tar.gz
tcl-bac2aebf1061014fdf5973b4d8d79544d24e74e0.tar.bz2
Test and fix for botch in binary string replace.
-rw-r--r--generic/tclStringObj.c1
-rw-r--r--tests/string.test6
2 files changed, 7 insertions, 0 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 9913160..2ebec64 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -3637,6 +3637,7 @@ TclStringReplace(
}
result = Tcl_NewByteArrayObj(NULL, numBytes - count + newBytes);
/* PANIC? */
+ Tcl_SetByteArrayLength(result, 0);
TclAppendBytesToByteArray(result, bytes, first);
TclAppendBytesToByteArray(result, iBytes, newBytes);
TclAppendBytesToByteArray(result, bytes + first + count,
diff --git a/tests/string.test b/tests/string.test
index f4b94de..bfd8d58 100644
--- a/tests/string.test
+++ b/tests/string.test
@@ -20,6 +20,9 @@ if {[lsearch [namespace children] ::tcltest] == -1} {
::tcltest::loadTestedCommands
catch [list package require -exact Tcltest [info patchlevel]]
+# Helper commands to test various optimizations, code paths, and special cases.
+proc makeByteArray {s} {binary format a* $s}
+
# Some tests require the testobj command
testConstraint testobj [expr {[info commands testobj] != {}}]
@@ -1396,6 +1399,9 @@ test string-14.18 {string replace} {
test string-14.19 {string replace} {
string replace {} -1 0 A
} A
+test string-14.20 {string replace} {
+ string replace [makeByteArray abcdefghijklmnop] end-10 end-2 [makeByteArray NEW]
+} abcdeNEWop
test string-15.1 {string tolower too few args} {
list [catch {string tolower} msg] $msg