summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2016-03-23 14:10:39 (GMT)
committerdgp <dgp@users.sourceforge.net>2016-03-23 14:10:39 (GMT)
commitdcf7da567cfeb4dd11639161b001e4c23459b4ad (patch)
tree40f96918f7eb54992ff10a6fc0ef7a4912c049ab
parent29c77a39fb1932211cd7b1e36a825f03616a9000 (diff)
downloadtcl-dcf7da567cfeb4dd11639161b001e4c23459b4ad.zip
tcl-dcf7da567cfeb4dd11639161b001e4c23459b4ad.tar.gz
tcl-dcf7da567cfeb4dd11639161b001e4c23459b4ad.tar.bz2
Revise Tcl_InitStringRep(); numBytes is unsigned. Only truncation permitted.
-rw-r--r--generic/tcl.decls3
-rw-r--r--generic/tclDecls.h4
-rw-r--r--generic/tclObj.c23
3 files changed, 16 insertions, 14 deletions
diff --git a/generic/tcl.decls b/generic/tcl.decls
index 24484a5..2bb49b9 100644
--- a/generic/tcl.decls
+++ b/generic/tcl.decls
@@ -2331,7 +2331,8 @@ declare 631 {
void Tcl_FreeIntRep(Tcl_Obj *objPtr)
}
declare 632 {
- char *Tcl_InitStringRep(Tcl_Obj *objPtr, const char *bytes, int numBytes)
+ char *Tcl_InitStringRep(Tcl_Obj *objPtr, const char *bytes,
+ unsigned int numBytes)
}
# ----- BASELINE -- FOR -- 8.7.0 ----- #
diff --git a/generic/tclDecls.h b/generic/tclDecls.h
index 3e2ac18..7114ad9 100644
--- a/generic/tclDecls.h
+++ b/generic/tclDecls.h
@@ -1820,7 +1820,7 @@ EXTERN void Tcl_ZlibStreamSetCompressionDictionary(
EXTERN void Tcl_FreeIntRep(Tcl_Obj *objPtr);
/* 632 */
EXTERN char * Tcl_InitStringRep(Tcl_Obj *objPtr, const char *bytes,
- int numBytes);
+ unsigned int numBytes);
typedef struct {
const struct TclPlatStubs *tclPlatStubs;
@@ -2488,7 +2488,7 @@ typedef struct TclStubs {
int (*tcl_FSUnloadFile) (Tcl_Interp *interp, Tcl_LoadHandle handlePtr); /* 629 */
void (*tcl_ZlibStreamSetCompressionDictionary) (Tcl_ZlibStream zhandle, Tcl_Obj *compressionDictionaryObj); /* 630 */
void (*tcl_FreeIntRep) (Tcl_Obj *objPtr); /* 631 */
- char * (*tcl_InitStringRep) (Tcl_Obj *objPtr, const char *bytes, int numBytes); /* 632 */
+ char * (*tcl_InitStringRep) (Tcl_Obj *objPtr, const char *bytes, unsigned int numBytes); /* 632 */
} TclStubs;
extern const TclStubs *tclStubsPtr;
diff --git a/generic/tclObj.c b/generic/tclObj.c
index 72c2340..3fb344e 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -1746,22 +1746,24 @@ char *
Tcl_InitStringRep(
Tcl_Obj *objPtr, /* Object whose string rep is to be set */
const char *bytes,
- int numBytes)
+ unsigned int numBytes)
{
- assert(numBytes >= 0);
-
assert(objPtr->bytes == NULL || bytes == NULL);
+ if (numBytes > INT_MAX) {
+ Tcl_Panic("max size for a Tcl value (%d bytes) exceeded", INT_MAX);
+ }
+
/* Allocate */
if (objPtr->bytes == NULL) {
/* Allocate only as empty - extend later if bytes copied */
objPtr->length = 0;
if (numBytes) {
- objPtr->bytes = (char *)ckalloc((unsigned)(numBytes+1));
+ objPtr->bytes = (char *)ckalloc(numBytes+1);
if (bytes) {
/* Copy */
- memcpy(objPtr->bytes, bytes, (unsigned) numBytes);
- objPtr->length = numBytes;
+ memcpy(objPtr->bytes, bytes, numBytes);
+ objPtr->length = (int) numBytes;
}
} else {
objPtr->bytes = tclEmptyStringRep;
@@ -1769,12 +1771,11 @@ Tcl_InitStringRep(
}
} else {
/* objPtr->bytes != NULL bytes == NULL - Truncate */
- assert(numBytes <= objPtr->length);
- if (objPtr->length > numBytes) {
- objPtr->bytes = (char *)ckrealloc(objPtr->bytes,
- (unsigned)(numBytes+1));
+ assert((int)numBytes <= objPtr->length);
+ if (objPtr->length > (int)numBytes) {
+ objPtr->bytes = (char *)ckrealloc(objPtr->bytes, numBytes+1);
+ objPtr->length = (int)numBytes;
}
- objPtr->length = numBytes;
}
/* Terminate */