summaryrefslogtreecommitdiffstats
path: root/generic/tclStringObj.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2014-01-27 17:35:27 (GMT)
committerdgp <dgp@users.sourceforge.net>2014-01-27 17:35:27 (GMT)
commit8703cd164100a81207d646099206dcc3acdf05bb (patch)
tree285907ad289fc50bd973bd5431433c43d4ff038a /generic/tclStringObj.c
parenta90c8f158fc3ddbccb467195a1ddbf7a71a851d5 (diff)
downloadtcl-8703cd164100a81207d646099206dcc3acdf05bb.zip
tcl-8703cd164100a81207d646099206dcc3acdf05bb.tar.gz
tcl-8703cd164100a81207d646099206dcc3acdf05bb.tar.bz2
Revise the Tcl_Append* machinery to tolerate NULL bytes to append.
Then have ReadChars() use that machinery to resize buffer receiving input, rather than invent its own version. Simplify ReadChars() callers.
Diffstat (limited to 'generic/tclStringObj.c')
-rw-r--r--generic/tclStringObj.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index a929d04..d96d814 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -1139,7 +1139,8 @@ Tcl_AppendLimitedToObj(
if (ellipsis == NULL) {
ellipsis = "...";
}
- toCopy = Tcl_UtfPrev(bytes+limit+1-strlen(ellipsis), bytes) - bytes;
+ toCopy = (bytes == NULL) ? limit
+ : Tcl_UtfPrev(bytes+limit+1-strlen(ellipsis), bytes) - bytes;
}
/*
@@ -1386,7 +1387,8 @@ AppendUnicodeToUnicodeRep(
* due to the reallocs below.
*/
int offset = -1;
- if (unicode >= stringPtr->unicode && unicode <= stringPtr->unicode
+ if (unicode && unicode >= stringPtr->unicode
+ && unicode <= stringPtr->unicode
+ stringPtr->uallocated / sizeof(Tcl_UniChar)) {
offset = unicode - stringPtr->unicode;
}
@@ -1405,8 +1407,10 @@ AppendUnicodeToUnicodeRep(
* trailing null.
*/
- memcpy(stringPtr->unicode + stringPtr->numChars, unicode,
- appendNumChars * sizeof(Tcl_UniChar));
+ if (unicode) {
+ memcpy(stringPtr->unicode + stringPtr->numChars, unicode,
+ appendNumChars * sizeof(Tcl_UniChar));
+ }
stringPtr->unicode[numChars] = 0;
stringPtr->numChars = numChars;
stringPtr->allocated = 0;
@@ -1478,8 +1482,8 @@ AppendUtfToUnicodeRep(
int numBytes) /* Number of bytes of "bytes" to convert. */
{
Tcl_DString dsPtr;
- int numChars;
- Tcl_UniChar *unicode;
+ int numChars = numBytes;
+ Tcl_UniChar *unicode = NULL;
if (numBytes < 0) {
numBytes = (bytes ? strlen(bytes) : 0);
@@ -1489,8 +1493,11 @@ AppendUtfToUnicodeRep(
}
Tcl_DStringInit(&dsPtr);
- numChars = Tcl_NumUtfChars(bytes, numBytes);
- unicode = (Tcl_UniChar *)Tcl_UtfToUniCharDString(bytes, numBytes, &dsPtr);
+ if (bytes) {
+ numChars = Tcl_NumUtfChars(bytes, numBytes);
+ unicode = (Tcl_UniChar *) Tcl_UtfToUniCharDString(bytes, numBytes,
+ &dsPtr);
+ }
AppendUnicodeToUnicodeRep(objPtr, unicode, numChars);
Tcl_DStringFree(&dsPtr);
}
@@ -1547,7 +1554,7 @@ AppendUtfToUtfRep(
* due to the reallocs below.
*/
int offset = -1;
- if (bytes >= objPtr->bytes
+ if (bytes && bytes >= objPtr->bytes
&& bytes <= objPtr->bytes + objPtr->length) {
offset = bytes - objPtr->bytes;
}
@@ -1585,7 +1592,9 @@ AppendUtfToUtfRep(
stringPtr->numChars = -1;
stringPtr->hasUnicode = 0;
- memcpy(objPtr->bytes + oldLength, bytes, (size_t) numBytes);
+ if (bytes) {
+ memcpy(objPtr->bytes + oldLength, bytes, (size_t) numBytes);
+ }
objPtr->bytes[newLength] = 0;
objPtr->length = newLength;
}