summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2011-03-06 21:40:49 (GMT)
committerdgp <dgp@users.sourceforge.net>2011-03-06 21:40:49 (GMT)
commita083ddc8208f8e9f625ef92db90f941262a260a6 (patch)
tree1e5dfeeb51ead4be18b7b7c5b8ea728553409480
parent030be92318aa1d4b37a84fae9614fe5a77f890ba (diff)
downloadtcl-a083ddc8208f8e9f625ef92db90f941262a260a6.zip
tcl-a083ddc8208f8e9f625ef92db90f941262a260a6.tar.gz
tcl-a083ddc8208f8e9f625ef92db90f941262a260a6.tar.bz2
* generic/tclBasic.c: More replacements of Tcl_UtfBackslash() calls
* generic/tclCmdMZ.c: with TclParseBackslash() where possible. * generic/tclCompExpr.c: * generic/tclCompile.c: * generic/tclUtil.c:
-rw-r--r--ChangeLog6
-rw-r--r--generic/tclBasic.c6
-rw-r--r--generic/tclCmdMZ.c2
-rw-r--r--generic/tclCompExpr.c4
-rw-r--r--generic/tclCompile.c4
-rw-r--r--generic/tclUtil.c29
6 files changed, 29 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index 9c09dcc..6d3ee7c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2011-03-06 Don Porter <dgp@users.sourceforge.net>
+ * generic/tclBasic.c: More replacements of Tcl_UtfBackslash() calls
+ * generic/tclCmdMZ.c: with TclParseBackslash() where possible.
+ * generic/tclCompExpr.c:
+ * generic/tclCompile.c:
+ * generic/tclUtil.c:
+
* generic/tclUtil.c (TclFindElement): Guard escape sequence scans
to not overrun the string end. [Bug 3192636]
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index 60cd23a..1c72e1b 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -3647,8 +3647,8 @@ EvalTokensStandard(interp, tokenPtr, count, line, clNextOuter, outerScript)
break;
case TCL_TOKEN_BS:
- length = Tcl_UtfBackslash(tokenPtr->start, (int *) NULL,
- buffer);
+ length = TclParseBackslash(tokenPtr->start, tokenPtr->size,
+ (int *) NULL, buffer);
p = buffer;
#ifdef TCL_TIP280
/*
@@ -4510,7 +4510,7 @@ TclAdvanceContinuations (line,clNextPtrPtr,loc)
/*
* Track the invisible continuation lines embedded in a script, if
* any. Here they are just spaces (already). They were removed by
- * EvalTokensStandard() via Tcl_UtfBackslash().
+ * EvalTokensStandard() via TclParseBackslash().
*
* *clNextPtrPtr <=> We have continuation lines to track.
* **clNextPtrPtr >= 0 <=> We are not beyond the last possible location.
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c
index fe8366c..ccf3bc6 100644
--- a/generic/tclCmdMZ.c
+++ b/generic/tclCmdMZ.c
@@ -2597,7 +2597,7 @@ Tcl_SubstObj(interp, objPtr, flags)
Tcl_AppendToObj(resultObj, old, p-old);
}
Tcl_AppendToObj(resultObj, buf,
- Tcl_UtfBackslash(p, &count, buf));
+ TclParseBackslash(p, length, &count, buf));
p += count; length -= count;
old = p;
} else {
diff --git a/generic/tclCompExpr.c b/generic/tclCompExpr.c
index a03b005..68533c5 100644
--- a/generic/tclCompExpr.c
+++ b/generic/tclCompExpr.c
@@ -387,8 +387,8 @@ CompileSubExpr(exprTokenPtr, infoPtr, envPtr)
break;
case TCL_TOKEN_BS:
- length = Tcl_UtfBackslash(tokenPtr->start, (int *) NULL,
- buffer);
+ length = TclParseBackslash(tokenPtr->start, tokenPtr->size,
+ (int *) NULL, buffer);
if (length > 0) {
objIndex = TclRegisterNewLiteral(envPtr, buffer, length);
} else {
diff --git a/generic/tclCompile.c b/generic/tclCompile.c
index 0678790..660a1f2 100644
--- a/generic/tclCompile.c
+++ b/generic/tclCompile.c
@@ -1571,8 +1571,8 @@ TclCompileTokens(interp, tokenPtr, count, envPtr)
break;
case TCL_TOKEN_BS:
- length = Tcl_UtfBackslash(tokenPtr->start, (int *) NULL,
- buffer);
+ length = TclParseBackslash(tokenPtr->start, tokenPtr->size,
+ (int *) NULL, buffer);
Tcl_DStringAppend(&textBuffer, buffer, length);
#ifdef TCL_TIP280
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 0dd4748..19332c8 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -341,11 +341,10 @@ TclFindElement(interp, list, listLength, elementPtr, nextPtr, sizePtr,
* Copy a string and eliminate any backslashes that aren't in braces.
*
* Results:
- * Count characters get copied from src to dst. Along the way, if
- * backslash sequences are found outside braces, the backslashes are
- * eliminated in the copy. After scanning count chars from source, a
- * null character is placed at the end of dst. Returns the number
- * of characters that got copied.
+ * Count bytes get copied from src to dst. Along the way, backslash
+ * sequences are substituted in the copy. After scanning count bytes
+ * from src, a null character is placed at the end of dst. Returns
+ * the number of bytes that got written to dst.
*
* Side effects:
* None.
@@ -355,26 +354,28 @@ TclFindElement(interp, list, listLength, elementPtr, nextPtr, sizePtr,
int
TclCopyAndCollapse(count, src, dst)
- int count; /* Number of characters to copy from src. */
+ int count; /* Number of bytes to copy from src. */
CONST char *src; /* Copy from here... */
char *dst; /* ... to here. */
{
- register char c;
- int numRead;
int newCount = 0;
- int backslashCount;
- for (c = *src; count > 0; src++, c = *src, count--) {
+ while (count > 0) {
+ char c = *src;
if (c == '\\') {
- backslashCount = Tcl_UtfBackslash(src, &numRead, dst);
+ int numRead;
+ int backslashCount = TclParseBackslash(src, count, &numRead, dst);
+
dst += backslashCount;
newCount += backslashCount;
- src += numRead-1;
- count -= numRead-1;
+ src += numRead;
+ count -= numRead;
} else {
*dst = c;
dst++;
newCount++;
+ src++;
+ count--;
}
}
*dst = 0;
@@ -643,7 +644,7 @@ Tcl_ScanCountedElement(string, length, flagPtr)
} else {
int size;
- Tcl_UtfBackslash(p, &size, NULL);
+ TclParseBackslash(p, lastChar - p, &size, NULL);
p += size-1;
flags |= USE_BRACES;
}