diff options
author | dgp <dgp@users.sourceforge.net> | 2003-03-12 18:04:35 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2003-03-12 18:04:35 (GMT) |
commit | 9a3b9da36ed9bc8d57ff9fff59bd316b54d97b66 (patch) | |
tree | fbaf7e14fa5c7f3dbfbd28b81d0e319ff2dfed7b /generic | |
parent | 8402e006eb6a2c17309cec126851bf9e3a8adeda (diff) | |
download | tcl-9a3b9da36ed9bc8d57ff9fff59bd316b54d97b66.zip tcl-9a3b9da36ed9bc8d57ff9fff59bd316b54d97b66.tar.gz tcl-9a3b9da36ed9bc8d57ff9fff59bd316b54d97b66.tar.bz2 |
* generic/tclCmdMZ.c (Tcl_SubstObj): Corrected and added test for
* tests/subst.test (subst-2.4): Tcl_SubstObj's incorrect
halting of substitution at the first \x00 byte. [Bug 685106]
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclCmdMZ.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index 2ae4819..939914a 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -14,7 +14,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclCmdMZ.c,v 1.82 2003/02/27 00:54:36 hobbs Exp $ + * RCS: @(#) $Id: tclCmdMZ.c,v 1.82.2.1 2003/03/12 18:04:39 dgp Exp $ */ #include "tclInt.h" @@ -2526,17 +2526,12 @@ Tcl_SubstObj(interp, objPtr, flags) { Tcl_Obj *resultObj; char *p, *old; + int length; - old = p = Tcl_GetString(objPtr); + old = p = Tcl_GetStringFromObj(objPtr, &length); resultObj = Tcl_NewStringObj("", 0); - while (1) { + while (length) { switch (*p) { - case 0: - if (p != old) { - Tcl_AppendToObj(resultObj, old, p-old); - } - return resultObj; - case '\\': if (flags & TCL_SUBST_BACKSLASHES) { char buf[TCL_UTF_MAX]; @@ -2547,10 +2542,10 @@ Tcl_SubstObj(interp, objPtr, flags) } Tcl_AppendToObj(resultObj, buf, Tcl_UtfBackslash(p, &count, buf)); - p += count; + p += count; length -= count; old = p; } else { - p++; + p++; length--; } break; @@ -2577,13 +2572,14 @@ Tcl_SubstObj(interp, objPtr, flags) * There isn't a variable name after all: the $ is * just a $. */ - p++; + p++; length--; break; } if (p != old) { Tcl_AppendToObj(resultObj, old, p-old); } p += parse.tokenPtr->size; + length -= parse.tokenPtr->size; code = Tcl_EvalTokensStandard(interp, parse.tokenPtr, parse.numTokens); if (code == TCL_ERROR) { @@ -2599,7 +2595,7 @@ Tcl_SubstObj(interp, objPtr, flags) Tcl_ResetResult(interp); old = p; } else { - p++; + p++; length--; } break; @@ -2624,16 +2620,21 @@ Tcl_SubstObj(interp, objPtr, flags) case TCL_CONTINUE: Tcl_ResetResult(interp); old = p = (p+1 + iPtr->termOffset + 1); + length -= (iPtr->termOffset + 2); } } else { - p++; + p++; length--; } break; default: - p++; + p++; length--; break; } } + if (p != old) { + Tcl_AppendToObj(resultObj, old, p-old); + } + return resultObj; errorResult: Tcl_DecrRefCount(resultObj); |