summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclStringObj.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index aeb4285..c3c85dc 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -1119,12 +1119,7 @@ Tcl_AppendLimitedToObj(
{
String *stringPtr;
int toCopy = 0;
-
- if (Tcl_IsShared(objPtr)) {
- Tcl_Panic("%s called with shared object", "Tcl_AppendLimitedToObj");
- }
-
- SetStringFromAny(NULL, objPtr);
+ int eLen = 0;
if (length < 0) {
length = (bytes ? strlen(bytes) : 0);
@@ -1132,6 +1127,9 @@ Tcl_AppendLimitedToObj(
if (length == 0) {
return;
}
+ if (limit <= 0) {
+ return;
+ }
if (length <= limit) {
toCopy = length;
@@ -1139,8 +1137,12 @@ Tcl_AppendLimitedToObj(
if (ellipsis == NULL) {
ellipsis = "...";
}
- toCopy = (bytes == NULL) ? limit
- : Tcl_UtfPrev(bytes+limit+1-strlen(ellipsis), bytes) - bytes;
+ eLen = strlen(ellipsis);
+ while (eLen > limit) {
+ eLen = Tcl_UtfPrev(ellipsis+eLen, ellipsis) - ellipsis;
+ }
+
+ toCopy = Tcl_UtfPrev(bytes+limit+1-eLen, bytes) - bytes;
}
/*
@@ -1149,6 +1151,11 @@ Tcl_AppendLimitedToObj(
* objPtr's string rep.
*/
+ if (Tcl_IsShared(objPtr)) {
+ Tcl_Panic("%s called with shared object", "Tcl_AppendLimitedToObj");
+ }
+
+ SetStringFromAny(NULL, objPtr);
stringPtr = GET_STRING(objPtr);
if (stringPtr->hasUnicode != 0) {
AppendUtfToUnicodeRep(objPtr, bytes, toCopy);
@@ -1162,9 +1169,9 @@ Tcl_AppendLimitedToObj(
stringPtr = GET_STRING(objPtr);
if (stringPtr->hasUnicode != 0) {
- AppendUtfToUnicodeRep(objPtr, ellipsis, -1);
+ AppendUtfToUnicodeRep(objPtr, ellipsis, eLen);
} else {
- AppendUtfToUtfRep(objPtr, ellipsis, -1);
+ AppendUtfToUtfRep(objPtr, ellipsis, eLen);
}
}