diff options
| author | dkf <donal.k.fellows@manchester.ac.uk> | 2018-08-26 11:07:37 (GMT) |
|---|---|---|
| committer | dkf <donal.k.fellows@manchester.ac.uk> | 2018-08-26 11:07:37 (GMT) |
| commit | d4d1014e7d4941e211860ee9864b7fbe829eae8d (patch) | |
| tree | e655b5ea3f4637db82bd76850b596cd9b68eac5e /generic/tclStringObj.c | |
| parent | f5efc84600e3a88460bdeb094d1cfa58ad5b3022 (diff) | |
| parent | b3993adcfb19f12c2fe6accbaec020a9599a6294 (diff) | |
| download | tcl-d4d1014e7d4941e211860ee9864b7fbe829eae8d.zip tcl-d4d1014e7d4941e211860ee9864b7fbe829eae8d.tar.gz tcl-d4d1014e7d4941e211860ee9864b7fbe829eae8d.tar.bz2 | |
merge core-8-branch
Diffstat (limited to 'generic/tclStringObj.c')
| -rw-r--r-- | generic/tclStringObj.c | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index f9ac8d7..f98180f 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -490,7 +490,7 @@ TclCheckEmptyString( Tcl_DictObjSize(NULL, objPtr, &length); return length == 0; } - + if (objPtr->bytes == NULL) { return TCL_EMPTYSTRING_UNKNOWN; } @@ -606,6 +606,8 @@ Tcl_GetUniChar( *---------------------------------------------------------------------- */ +#ifndef TCL_NO_DEPRECATED +#undef Tcl_GetUnicode Tcl_UniChar * Tcl_GetUnicode( Tcl_Obj *objPtr) /* The object to find the unicode string @@ -613,6 +615,7 @@ Tcl_GetUnicode( { return Tcl_GetUnicodeFromObj(objPtr, NULL); } +#endif /* TCL_NO_DEPRECATED */ /* *---------------------------------------------------------------------- @@ -1901,6 +1904,11 @@ Tcl_AppendFormatToObj( width = 0; if (isdigit(UCHAR(ch))) { width = strtoul(format, &end, 10); + if (width < 0) { + msg = overflow; + errCode = "OVERFLOW"; + goto errorMsg; + } format = end; step = TclUtfToUniChar(format, &ch); } else if (ch == '*') { @@ -2040,6 +2048,10 @@ Tcl_AppendFormatToObj( goto error; } length = Tcl_UniCharToUtf(code, buf); + if (!length) { + /* Special case for handling upper surrogates. */ + length = Tcl_UniCharToUtf(-1, buf); + } segment = Tcl_NewStringObj(buf, length); Tcl_IncrRefCount(segment); allocSegment = 1; @@ -3058,15 +3070,21 @@ TclStringCat( * Result will be pure byte array. Pre-size it */ + int numBytes; ov = objv; oc = objc; do { Tcl_Obj *objPtr = *ov++; - if (objPtr->bytes == NULL) { - int numBytes; + /* + * Every argument is either a bytearray with a ("pure") + * value we know we can safely use, or it is an empty string. + * We don't need to count bytes for the empty strings. + */ + if (TclIsPureByteArray(objPtr)) { Tcl_GetByteArrayFromObj(objPtr, &numBytes); /* PANIC? */ + if (numBytes) { last = objc - oc; if (length == 0) { @@ -3218,7 +3236,13 @@ TclStringCat( while (objc--) { Tcl_Obj *objPtr = *objv++; - if (objPtr->bytes == NULL) { + /* + * Every argument is either a bytearray with a ("pure") + * value we know we can safely use, or it is an empty string. + * We don't need to copy bytes from the empty strings. + */ + + if (TclIsPureByteArray(objPtr)) { int more; unsigned char *src = Tcl_GetByteArrayFromObj(objPtr, &more); memcpy(dst, src, (size_t) more); @@ -3549,7 +3573,7 @@ TclStringFirst( start = 0; } if (ln == 0) { - /* We don't find empty substrings. Bizarre! + /* We don't find empty substrings. Bizarre! * Whenever this routine is turned into a proper substring * finder, change to `return start` after limits imposed. */ return -1; @@ -3946,7 +3970,7 @@ TclStringReplace( result = Tcl_NewByteArrayObj(NULL, numBytes - count + newBytes); /* PANIC? */ Tcl_SetByteArrayLength(result, 0); - TclAppendBytesToByteArray(result, bytes, first); + TclAppendBytesToByteArray(result, bytes, first); TclAppendBytesToByteArray(result, iBytes, newBytes); TclAppendBytesToByteArray(result, bytes + first + count, numBytes - count - first); @@ -3968,7 +3992,7 @@ TclStringReplace( Tcl_UniChar *ustring = Tcl_GetUnicodeFromObj(objPtr, &numChars); /* TODO: Is there an in-place option worth pursuing here? */ - + result = Tcl_NewUnicodeObj(ustring, first); if (insertPtr) { Tcl_AppendObjToObj(result, insertPtr); |
