From 4d7b9162e578238f275688adcef5d56242b8ae7e Mon Sep 17 00:00:00 2001 From: dkf Date: Fri, 17 Feb 2017 09:20:49 +0000 Subject: Stop problems with representation smashes. --- generic/tclCmdMZ.c | 7 +++++++ tests/regexp.test | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index d6d0152..110de4c 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -811,6 +811,13 @@ Tcl_RegsubObjCmd( Tcl_AppendObjToObj(resultPtr, Tcl_GetObjResult(interp)); Tcl_ResetResult(interp); + /* + * Refetch the unicode, in case the representation was smashed by + * the user code. + */ + + wstring = Tcl_GetUnicodeFromObj(objPtr, &wlen); + offset += end; if (end == 0 || start == end) { /* diff --git a/tests/regexp.test b/tests/regexp.test index 6c3d774..ad770fa 100644 --- a/tests/regexp.test +++ b/tests/regexp.test @@ -1143,6 +1143,12 @@ test regexp-27.5 {regsub -command} { test regexp-27.6 {regsub -command} { regsub -command -all {(.)(.)} {abcdef} {list ,} } {, ab a b, cd c d, ef e f} +test regexp-27.7 {regsub -command representation smash} { + set ::s {123=456 789} + regsub -command -all {\d+} $::s {apply {n { + expr {[llength $::s] + $n} + }}} +} {125=458 791} # cleanup ::tcltest::cleanupTests -- cgit v0.12