summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2018-09-28 18:19:04 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2018-09-28 18:19:04 (GMT)
commit37b9b4dedcc82238e69c508b7631f2a28952baea (patch)
tree7d0038929ef82d8474e618ea987d942fc986f257
parent45d39f04442dea70448b254d80cfbe15d6c488ed (diff)
downloadtcl-37b9b4dedcc82238e69c508b7631f2a28952baea.zip
tcl-37b9b4dedcc82238e69c508b7631f2a28952baea.tar.gz
tcl-37b9b4dedcc82238e69c508b7631f2a28952baea.tar.bz2
code/doc cleanup
-rw-r--r--doc/DString.32
-rw-r--r--generic/tclPreserve.c10
-rw-r--r--generic/tclUtil.c33
3 files changed, 20 insertions, 25 deletions
diff --git a/doc/DString.3 b/doc/DString.3
index d35e688..25c4c63 100644
--- a/doc/DString.3
+++ b/doc/DString.3
@@ -26,7 +26,7 @@ char *
.sp
\fBTcl_DStringEndSublist\fR(\fIdsPtr\fR)
.sp
-int
+size_t
\fBTcl_DStringLength\fR(\fIdsPtr\fR)
.sp
char *
diff --git a/generic/tclPreserve.c b/generic/tclPreserve.c
index ad7a443..695eeb9 100644
--- a/generic/tclPreserve.c
+++ b/generic/tclPreserve.c
@@ -37,9 +37,9 @@ typedef struct {
*/
static Reference *refArray = NULL; /* First in array of references. */
-static int spaceAvl = 0; /* Total number of structures available at
+static size_t spaceAvl = 0; /* Total number of structures available at
* *firstRefPtr. */
-static int inUse = 0; /* Count of structures currently in use in
+static size_t inUse = 0; /* Count of structures currently in use in
* refArray. */
TCL_DECLARE_MUTEX(preserveMutex)/* To protect the above statics */
@@ -121,7 +121,7 @@ Tcl_Preserve(
ClientData clientData) /* Pointer to malloc'ed block of memory. */
{
Reference *refPtr;
- int i;
+ size_t i;
/*
* See if there is already a reference for this pointer. If so, just
@@ -184,7 +184,7 @@ Tcl_Release(
ClientData clientData) /* Pointer to malloc'ed block of memory. */
{
Reference *refPtr;
- int i;
+ size_t i;
Tcl_MutexLock(&preserveMutex);
for (i=0, refPtr=refArray ; i<inUse ; i++, refPtr++) {
@@ -264,7 +264,7 @@ Tcl_EventuallyFree(
Tcl_FreeProc *freeProc) /* Function to actually do free. */
{
Reference *refPtr;
- int i;
+ size_t i;
/*
* See if there is a reference for this pointer. If so, set its "mustFree"
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 85f3e74..93242e4 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -897,7 +897,7 @@ Tcl_SplitList(
}
argv[i] = p;
if (literal) {
- memcpy(p, element, (size_t) elSize);
+ memcpy(p, element, elSize);
p += elSize;
*p = 0;
p++;
@@ -973,7 +973,7 @@ Tcl_ScanCountedElement(
* Tcl_ConvertElement. */
{
char flags = CONVERT_ANY;
- size_t numBytes = TclScanElement(src, length, &flags);
+ int numBytes = TclScanElement(src, length, &flags);
*flagPtr = flags;
return numBytes;
@@ -1025,7 +1025,7 @@ TclScanElement(
int extra = 0; /* Count of number of extra bytes needed for
* formatted element, assuming we use escape
* sequences in formatting. */
- size_t bytesNeeded; /* Buffer length computed to complete the
+ int 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 */
@@ -1269,6 +1269,9 @@ TclScanElement(
*flagPtr = CONVERT_NONE;
overflowCheck:
+ if (bytesNeeded < 0) {
+ Tcl_Panic("TclScanElement: string length overflow");
+ }
return bytesNeeded;
}
@@ -1650,9 +1653,9 @@ UtfWellFormedEnd(
static inline int
TrimRight(
const char *bytes, /* String to be trimmed... */
- size_t numBytes, /* ...and its length in bytes */
+ int numBytes, /* ...and its length in bytes */
const char *trim, /* String of trim characters... */
- size_t numTrim) /* ...and its length in bytes */
+ int numTrim) /* ...and its length in bytes */
{
const char *p = bytes + numBytes;
int pInc;
@@ -1911,8 +1914,8 @@ Tcl_Concat(
int argc, /* Number of strings to concatenate. */
const char *const *argv) /* Array of strings to concatenate. */
{
- int i, needSpace = 0;
- size_t bytesNeeded = 0;
+ int i;
+ size_t needSpace = 0, bytesNeeded = 0;
char *result, *p;
/*
@@ -1940,8 +1943,7 @@ Tcl_Concat(
result = Tcl_Alloc(bytesNeeded + argc);
for (p = result, i = 0; i < argc; i++) {
- size_t triml, trimr;
- int elemLength;
+ size_t triml, trimr, elemLength;
const char *element;
element = argv[i];
@@ -2678,7 +2680,7 @@ Tcl_DStringAppend(
memcpy(newString, dsPtr->string, dsPtr->length);
dsPtr->string = newString;
} else {
- int offset = -1;
+ size_t offset = (size_t)-1;
/* See [16896d49fd] */
if (bytes >= dsPtr->string
@@ -2688,7 +2690,7 @@ Tcl_DStringAppend(
dsPtr->string = Tcl_Realloc(dsPtr->string, dsPtr->spaceAvl);
- if (offset >= 0) {
+ if (offset != (size_t)-1) {
bytes = dsPtr->string + offset;
}
}
@@ -2845,13 +2847,6 @@ Tcl_DStringSetLength(
{
size_t newsize;
-#if defined(_WIN32) || defined(__CYGWIN__)
- /* The "registry" extension calls this function with length -2 or -1,
- * so we have to take that into account. Should actually be fixed there! */
- if (length >= (size_t)-2) {
- length = 0;
- }
-#endif
if (length >= dsPtr->spaceAvl) {
/*
* There are two interesting cases here. In the first case, the user
@@ -3988,7 +3983,7 @@ TclGetProcessGlobalValue(
Tcl_Free(pgvPtr->value);
pgvPtr->value = Tcl_Alloc(Tcl_DStringLength(&newValue) + 1);
memcpy(pgvPtr->value, Tcl_DStringValue(&newValue),
- (size_t) Tcl_DStringLength(&newValue) + 1);
+ Tcl_DStringLength(&newValue) + 1);
Tcl_DStringFree(&newValue);
Tcl_FreeEncoding(pgvPtr->encoding);
pgvPtr->encoding = current;