summaryrefslogtreecommitdiffstats
path: root/generic/tclStringObj.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclStringObj.c')
-rw-r--r--generic/tclStringObj.c96
1 files changed, 48 insertions, 48 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 9b72d52..57f368a 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -45,27 +45,27 @@
static void AppendPrintfToObjVA(Tcl_Obj *objPtr,
const char *format, va_list argList);
static void AppendUnicodeToUnicodeRep(Tcl_Obj *objPtr,
- const Tcl_UniChar *unicode, int appendNumChars);
+ const Tcl_UniChar *unicode, size_t appendNumChars);
static void AppendUnicodeToUtfRep(Tcl_Obj *objPtr,
- const Tcl_UniChar *unicode, int numChars);
+ const Tcl_UniChar *unicode, size_t numChars);
static void AppendUtfToUnicodeRep(Tcl_Obj *objPtr,
- const char *bytes, int numBytes);
+ const char *bytes, size_t numBytes);
static void AppendUtfToUtfRep(Tcl_Obj *objPtr,
- const char *bytes, int numBytes);
+ const char *bytes, size_t numBytes);
static void DupStringInternalRep(Tcl_Obj *objPtr,
Tcl_Obj *copyPtr);
static int ExtendStringRepWithUnicode(Tcl_Obj *objPtr,
- const Tcl_UniChar *unicode, int numChars);
+ const Tcl_UniChar *unicode, size_t numChars);
static void ExtendUnicodeRepWithString(Tcl_Obj *objPtr,
- const char *bytes, int numBytes,
- int numAppendChars);
+ const char *bytes, size_t numBytes,
+ size_t numAppendChars);
static void FillUnicodeRep(Tcl_Obj *objPtr);
static void FreeStringInternalRep(Tcl_Obj *objPtr);
-static void GrowStringBuffer(Tcl_Obj *objPtr, int needed, int flag);
-static void GrowUnicodeBuffer(Tcl_Obj *objPtr, int needed);
+static void GrowStringBuffer(Tcl_Obj *objPtr, size_t needed, int flag);
+static void GrowUnicodeBuffer(Tcl_Obj *objPtr, size_t needed);
static int SetStringFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
static void SetUnicodeObj(Tcl_Obj *objPtr,
- const Tcl_UniChar *unicode, int numChars);
+ const Tcl_UniChar *unicode, size_t numChars);
static size_t UnicodeLength(const Tcl_UniChar *unicode);
static void UpdateStringOfString(Tcl_Obj *objPtr);
@@ -122,7 +122,7 @@ const Tcl_ObjType tclStringType = {
static void
GrowStringBuffer(
Tcl_Obj *objPtr,
- int needed,
+ size_t needed,
int flag)
{
/*
@@ -134,14 +134,14 @@ GrowStringBuffer(
String *stringPtr = GET_STRING(objPtr);
char *ptr = NULL;
- int attempt;
+ size_t attempt;
if (objPtr->bytes == tclEmptyStringRep) {
objPtr->bytes = NULL;
}
if (flag == 0 || stringPtr->allocated > 0) {
attempt = 2 * needed;
- if (attempt >= 0) {
+ if ((int)attempt >= 0) {
ptr = attemptckrealloc(objPtr->bytes, attempt + 1);
}
if (ptr == NULL) {
@@ -150,9 +150,9 @@ GrowStringBuffer(
* overflow into invalid argument values for attempt.
*/
- unsigned int limit = INT_MAX - needed;
- unsigned int extra = needed - objPtr->length + TCL_MIN_GROWTH;
- int growth = (int) ((extra > limit) ? limit : extra);
+ size_t limit = INT_MAX - needed;
+ size_t extra = needed - objPtr->length + TCL_MIN_GROWTH;
+ size_t growth = (extra > limit) ? limit : extra;
attempt = needed + growth;
ptr = attemptckrealloc(objPtr->bytes, attempt + 1);
@@ -173,7 +173,7 @@ GrowStringBuffer(
static void
GrowUnicodeBuffer(
Tcl_Obj *objPtr,
- int needed)
+ size_t needed)
{
/*
* Pre-conditions:
@@ -183,7 +183,7 @@ GrowUnicodeBuffer(
*/
String *ptr = NULL, *stringPtr = GET_STRING(objPtr);
- int attempt;
+ size_t attempt;
if (stringPtr->maxChars > 0) {
/*
@@ -191,7 +191,7 @@ GrowUnicodeBuffer(
*/
attempt = 2 * needed;
- if ((size_t)attempt <= STRING_MAXCHARS) {
+ if (attempt <= STRING_MAXCHARS) {
ptr = stringAttemptRealloc(stringPtr, attempt);
}
if (ptr == NULL) {
@@ -200,10 +200,10 @@ GrowUnicodeBuffer(
* overflow into invalid argument values for attempt.
*/
- unsigned int limit = STRING_MAXCHARS - needed;
- unsigned int extra = needed - stringPtr->numChars
+ size_t limit = STRING_MAXCHARS - needed;
+ size_t extra = needed - stringPtr->numChars
+ TCL_MIN_UNICHAR_GROWTH;
- int growth = (int) ((extra > limit) ? limit : extra);
+ size_t growth = (extra > limit) ? limit : extra;
attempt = needed + growth;
ptr = stringAttemptRealloc(stringPtr, attempt);
@@ -489,7 +489,7 @@ Tcl_GetUniChar(
* If numChars is unknown, compute it.
*/
- if (stringPtr->numChars == -1) {
+ if (stringPtr->numChars == (size_t)-1) {
TclNumUtfChars(stringPtr->numChars, objPtr->bytes, objPtr->length);
}
if (stringPtr->numChars == objPtr->length) {
@@ -623,7 +623,7 @@ Tcl_GetRange(
* If numChars is unknown, compute it.
*/
- if (stringPtr->numChars == -1) {
+ if (stringPtr->numChars == (size_t)-1) {
TclNumUtfChars(stringPtr->numChars, objPtr->bytes, objPtr->length);
}
if (stringPtr->numChars == objPtr->length) {
@@ -969,12 +969,12 @@ SetUnicodeObj(
Tcl_Obj *objPtr, /* The object to set the string of. */
const Tcl_UniChar *unicode, /* The unicode string used to initialize the
* object. */
- int numChars) /* Number of characters in the unicode
+ size_t numChars) /* Number of characters in the unicode
* string. */
{
String *stringPtr;
- if (numChars < 0) {
+ if (numChars == (size_t)-1) {
numChars = UnicodeLength(unicode);
}
@@ -1050,7 +1050,7 @@ Tcl_AppendLimitedToObj(
ellipsis = "...";
}
toCopy = (bytes == NULL) ? limit
- : Tcl_UtfPrev(bytes+limit+1-strlen(ellipsis), bytes) - bytes;
+ : (size_t)(Tcl_UtfPrev(bytes+limit+1-strlen(ellipsis), bytes) - bytes);
}
/*
@@ -1315,12 +1315,12 @@ static void
AppendUnicodeToUnicodeRep(
Tcl_Obj *objPtr, /* Points to the object to append to. */
const Tcl_UniChar *unicode, /* String to append. */
- int appendNumChars) /* Number of chars of "unicode" to append. */
+ size_t appendNumChars) /* Number of chars of "unicode" to append. */
{
String *stringPtr;
- int numChars;
+ size_t numChars;
- if (appendNumChars < 0) {
+ if (appendNumChars == (size_t)-1) {
appendNumChars = UnicodeLength(unicode);
}
if (appendNumChars == 0) {
@@ -1342,7 +1342,7 @@ AppendUnicodeToUnicodeRep(
stringCheckLimits(numChars);
if (numChars > stringPtr->maxChars) {
- int offset = -1;
+ size_t offset = (size_t)-1;
/*
* Protect against case where unicode points into the existing
@@ -1362,7 +1362,7 @@ AppendUnicodeToUnicodeRep(
* Relocate unicode if needed; see above.
*/
- if (offset >= 0) {
+ if (offset != (size_t)-1) {
unicode = stringPtr->unicode + offset;
}
}
@@ -1404,13 +1404,13 @@ static void
AppendUnicodeToUtfRep(
Tcl_Obj *objPtr, /* Points to the object to append to. */
const Tcl_UniChar *unicode, /* String to convert to UTF. */
- int numChars) /* Number of chars of "unicode" to convert. */
+ size_t numChars) /* Number of chars of "unicode" to convert. */
{
String *stringPtr = GET_STRING(objPtr);
numChars = ExtendStringRepWithUnicode(objPtr, unicode, numChars);
- if (stringPtr->numChars != -1) {
+ if (stringPtr->numChars != (size_t)-1) {
stringPtr->numChars += numChars;
}
}
@@ -1437,7 +1437,7 @@ static void
AppendUtfToUnicodeRep(
Tcl_Obj *objPtr, /* Points to the object to append to. */
const char *bytes, /* String to convert to Unicode. */
- int numBytes) /* Number of bytes of "bytes" to convert. */
+ size_t numBytes) /* Number of bytes of "bytes" to convert. */
{
String *stringPtr;
@@ -1473,10 +1473,10 @@ static void
AppendUtfToUtfRep(
Tcl_Obj *objPtr, /* Points to the object to append to. */
const char *bytes, /* String to append. */
- int numBytes) /* Number of bytes of "bytes" to append. */
+ size_t numBytes) /* Number of bytes of "bytes" to append. */
{
String *stringPtr;
- int newLength, oldLength;
+ size_t newLength, oldLength;
if (numBytes == 0) {
return;
@@ -1492,7 +1492,7 @@ AppendUtfToUtfRep(
}
oldLength = objPtr->length;
newLength = numBytes + oldLength;
- if (newLength < 0) {
+ if ((int)newLength < 0) {
Tcl_Panic("max size for a Tcl value (%d bytes) exceeded", INT_MAX);
}
@@ -2769,17 +2769,17 @@ static void
ExtendUnicodeRepWithString(
Tcl_Obj *objPtr,
const char *bytes,
- int numBytes,
- int numAppendChars)
+ size_t numBytes,
+ size_t numAppendChars)
{
String *stringPtr = GET_STRING(objPtr);
- int needed, numOrigChars = 0;
+ size_t needed, numOrigChars = 0;
Tcl_UniChar *dst;
if (stringPtr->hasUnicode) {
numOrigChars = stringPtr->numChars;
}
- if (numAppendChars == -1) {
+ if (numAppendChars == (size_t)-1) {
TclNumUtfChars(numAppendChars, bytes, numBytes);
}
needed = numOrigChars + numAppendChars;
@@ -2830,7 +2830,7 @@ DupStringInternalRep(
String *srcStringPtr = GET_STRING(srcPtr);
String *copyStringPtr = NULL;
- if (srcStringPtr->numChars == -1) {
+ if (srcStringPtr->numChars == (size_t)-1) {
/*
* The String struct in the source value holds zero useful data. Don't
* bother copying it. Don't even bother allocating space in which to
@@ -2960,17 +2960,17 @@ static int
ExtendStringRepWithUnicode(
Tcl_Obj *objPtr,
const Tcl_UniChar *unicode,
- int numChars)
+ size_t numChars)
{
/*
* Pre-condition: this is the "string" Tcl_ObjType.
*/
- int i, origLength, size = 0;
+ size_t i, origLength, size = 0;
char *dst;
String *stringPtr = GET_STRING(objPtr);
- if (numChars < 0) {
+ if (numChars == (size_t)-1) {
numChars = UnicodeLength(unicode);
}
@@ -2987,7 +2987,7 @@ ExtendStringRepWithUnicode(
* Quick cheap check in case we have more than enough room.
*/
- if (numChars <= (INT_MAX - size)/TCL_UTF_MAX
+ if (numChars <= (size_t)((INT_MAX - size)/TCL_UTF_MAX)
&& stringPtr->allocated >= size + numChars * TCL_UTF_MAX) {
goto copyBytes;
}
@@ -2995,7 +2995,7 @@ ExtendStringRepWithUnicode(
for (i = 0; i < numChars && size >= 0; i++) {
size += TclUtfCount(unicode[i]);
}
- if (size < 0) {
+ if ((int)size < 0) {
Tcl_Panic("max size for a Tcl value (%d bytes) exceeded", INT_MAX);
}