diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-04-14 10:17:31 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-04-14 10:17:31 (GMT) |
commit | e59db7e00e94f016d7c222aea7603dbbc8eecb4e (patch) | |
tree | 49eea3f1d82a1ac023889575a2e07d7643ad4b41 /generic/tclStringObj.c | |
parent | 2f98c2ea4d9b29dc3a797522a457585ac5865388 (diff) | |
parent | 920063dce71227734c3cd38eea46fd644ec37ded (diff) | |
download | tcl-e59db7e00e94f016d7c222aea7603dbbc8eecb4e.zip tcl-e59db7e00e94f016d7c222aea7603dbbc8eecb4e.tar.gz tcl-e59db7e00e94f016d7c222aea7603dbbc8eecb4e.tar.bz2 |
Merge 8.6
Diffstat (limited to 'generic/tclStringObj.c')
-rw-r--r-- | generic/tclStringObj.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index c6d5323..2025674 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -1151,10 +1151,7 @@ Tcl_AppendLimitedToObj( { String *stringPtr; int toCopy = 0; - - if (Tcl_IsShared(objPtr)) { - Tcl_Panic("%s called with shared object", "Tcl_AppendLimitedToObj"); - } + int eLen = 0; if (length < 0) { length = (bytes ? strlen(bytes) : 0); @@ -1162,6 +1159,9 @@ Tcl_AppendLimitedToObj( if (length == 0) { return; } + if (limit <= 0) { + return; + } if (length <= limit) { toCopy = length; @@ -1169,8 +1169,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; } /* @@ -1179,6 +1183,10 @@ 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); @@ -1194,9 +1202,9 @@ Tcl_AppendLimitedToObj( stringPtr = GET_STRING(objPtr); if (stringPtr->hasUnicode && stringPtr->numChars > 0) { - AppendUtfToUnicodeRep(objPtr, ellipsis, strlen(ellipsis)); + AppendUtfToUnicodeRep(objPtr, ellipsis, eLen); } else { - AppendUtfToUtfRep(objPtr, ellipsis, strlen(ellipsis)); + AppendUtfToUtfRep(objPtr, ellipsis, eLen); } } |