diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-02-05 21:35:10 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-02-05 21:35:10 (GMT) |
commit | 2dad23ad65d5cf76fa7e2516a6702a8a6ff34723 (patch) | |
tree | 0b80be8eba412258b3fa4c109b6b554863d27378 /generic/tclUtil.c | |
parent | eee14742522aed25744851879c80a96134de7369 (diff) | |
download | tcl-2dad23ad65d5cf76fa7e2516a6702a8a6ff34723.zip tcl-2dad23ad65d5cf76fa7e2516a6702a8a6ff34723.tar.gz tcl-2dad23ad65d5cf76fa7e2516a6702a8a6ff34723.tar.bz2 |
More size_t-related consolidations. Now regexp can handle strings >2GB and more. Remove many type-casts which are not necessary any more.
Diffstat (limited to 'generic/tclUtil.c')
-rw-r--r-- | generic/tclUtil.c | 63 |
1 files changed, 28 insertions, 35 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 6481283..4b3a5cb 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -1027,7 +1027,7 @@ TclScanElement( int extra = 0; /* Count of number of extra bytes needed for * formatted element, assuming we use escape * sequences in formatting. */ - int bytesNeeded; /* Buffer length computed to complete the + size_t bytesNeeded; /* Buffer length computed to complete the * element formatting in the selected mode. */ #if COMPAT int preferEscape = 0; /* Use preferences to track whether to use */ @@ -1197,7 +1197,7 @@ TclScanElement( bytesNeeded++; } *flagPtr = CONVERT_ESCAPE; - goto overflowCheck; + return bytesNeeded; } if (*flagPtr & CONVERT_ANY) { /* @@ -1245,7 +1245,7 @@ TclScanElement( bytesNeeded += braceCount; } *flagPtr = CONVERT_MASK; - goto overflowCheck; + return bytesNeeded; } #endif /* COMPAT */ if (*flagPtr & TCL_DONT_USE_BRACES) { @@ -1271,7 +1271,7 @@ TclScanElement( bytesNeeded += 2; } *flagPtr = CONVERT_BRACE; - goto overflowCheck; + return bytesNeeded; } /* @@ -1286,11 +1286,6 @@ TclScanElement( bytesNeeded += 2; } *flagPtr = CONVERT_NONE; - - overflowCheck: - if (bytesNeeded < 0) { - Tcl_Panic("TclScanElement: string length overflow"); - } return bytesNeeded; } @@ -1669,15 +1664,15 @@ UtfWellFormedEnd( *---------------------------------------------------------------------- */ -static inline int +static inline size_t TrimRight( const char *bytes, /* String to be trimmed... */ - int numBytes, /* ...and its length in bytes */ + size_t numBytes, /* ...and its length in bytes */ const char *trim, /* String of trim characters... */ - int numTrim) /* ...and its length in bytes */ + size_t numTrim) /* ...and its length in bytes */ { const char *p = bytes + numBytes; - int pInc; + size_t pInc; Tcl_UniChar ch1 = 0, ch2 = 0; /* @@ -1686,7 +1681,7 @@ TrimRight( do { const char *q = trim; - int bytesLeft = numTrim; + size_t bytesLeft = numTrim; p = Tcl_UtfPrev(p, bytes); pInc = TclUtfToUniChar(p, &ch1); @@ -1696,7 +1691,7 @@ TrimRight( */ do { - int qInc = TclUtfToUniChar(q, &ch2); + size_t qInc = TclUtfToUniChar(q, &ch2); if (ch1 == ch2) { break; @@ -1783,16 +1778,16 @@ TrimLeft( */ do { - int pInc = TclUtfToUniChar(p, &ch1); + size_t pInc = TclUtfToUniChar(p, &ch1); const char *q = trim; - int bytesLeft = numTrim; + size_t bytesLeft = numTrim; /* * Inner loop: scan trim string for match to current character. */ do { - int qInc = TclUtfToUniChar(q, &ch2); + size_t qInc = TclUtfToUniChar(q, &ch2); if (ch1 == ch2) { break; @@ -1992,7 +1987,7 @@ Tcl_Concat( if (needSpace) { *p++ = ' '; } - memcpy(p, element, (size_t) elemLength); + memcpy(p, element, elemLength); p += elemLength; needSpace = 1; } @@ -2041,8 +2036,7 @@ Tcl_ConcatObj( if (TclListObjIsCanonical(objPtr)) { continue; } - TclGetString(objPtr); - length = objPtr->length; + (void)TclGetStringFromObj(objPtr, &length); if (length > 0) { break; } @@ -2079,8 +2073,7 @@ Tcl_ConcatObj( */ for (i = 0; i < objc; i++) { - element = TclGetString(objv[i]); - elemLength = objv[i]->length; + element = TclGetStringFromObj(objv[i], &elemLength); bytesNeeded += elemLength; } @@ -2097,8 +2090,7 @@ Tcl_ConcatObj( for (i = 0; i < objc; i++) { size_t triml, trimr; - element = TclGetString(objv[i]); - elemLength = objv[i]->length; + element = TclGetStringFromObj(objv[i], &elemLength); /* Trim away the leading/trailing whitespace. */ triml = TclTrim(element, elemLength, CONCAT_TRIM_SET, @@ -2741,9 +2733,10 @@ TclDStringAppendObj( Tcl_DString *dsPtr, Tcl_Obj *objPtr) { - char *bytes = TclGetString(objPtr); + size_t length; + const char *bytes = TclGetStringFromObj(objPtr, &length); - return Tcl_DStringAppend(dsPtr, bytes, objPtr->length); + return Tcl_DStringAppend(dsPtr, bytes, length); } char * @@ -3637,13 +3630,13 @@ TclGetIntForIndex( Tcl_WideInt wide; /* Use platform-related size_t to wide-int to consider negative value - * ((size_t)-1) if wide-int and size_t have different dimensions. */ + * TCL_INDEX_NONE if wide-int and size_t have different dimensions. */ if (GetWideForIndex(interp, objPtr, TclWideIntFromSize(endValue), - &wide) == TCL_ERROR) { + &wide) == TCL_ERROR) { return TCL_ERROR; } if (wide < 0) { - *indexPtr = -1; + *indexPtr = TCL_INDEX_NONE; } else if (wide > INT_MAX) { *indexPtr = INT_MAX; } else { @@ -3825,7 +3818,7 @@ TclIndexEncode( /* We parsed a value in the range WIDE_MIN...WIDE_MAX */ wide = (*(Tcl_WideInt *)cd); integerEncode: - if (wide < TCL_INDEX_START) { + if (wide < 0) { /* All negative absolute indices are "before the beginning" */ idx = before; } else if (wide >= INT_MAX) { @@ -3845,13 +3838,13 @@ TclIndexEncode( * All end+positive or end-negative expressions * always indicate "after the end". */ - idx = after; - } else if (wide < INT_MIN - TCL_INDEX_END) { + idx = (int) after; + } else if (wide < INT_MIN - (int) TCL_INDEX_END) { /* These indices always indicate "before the beginning */ - idx = before; + idx = (int) before; } else { /* Encoded end-positive (or end+negative) are offset */ - idx = (int)wide + TCL_INDEX_END; + idx = (int) wide + (int) TCL_INDEX_END; } /* TODO: Consider flag to suppress repeated end-offset parse. */ |