Attachment "hash_alloc.patch" to
ticket [521950ffff]
added by
mdejong
2002-02-24 09:46:03.
2002-02-23 Mo DeJong <[email protected]>
* generic/tclHash.c (AllocArrayEntry, AllocStringEntry):
Before invoking ckalloc when creating a Tcl_HashEntry,
check that the amount of memory being allocated is
at least as large as sizeof(Tcl_HashEntry). The previous
code was allocating memory regions that were one
or two bytes short.
Index: generic/tclHash.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclHash.c,v
retrieving revision 1.10
diff -u -2 -r1.10 tclHash.c
--- generic/tclHash.c 25 Jan 2002 21:36:09 -0000 1.10
+++ generic/tclHash.c 24 Feb 2002 02:39:31 -0000
@@ -815,9 +815,12 @@
Tcl_HashEntry *hPtr;
int count;
+ unsigned int size;
count = tablePtr->keyType;
- hPtr = (Tcl_HashEntry *) ckalloc((unsigned) (sizeof(Tcl_HashEntry)
- + (count*sizeof(int)) - sizeof(hPtr->key)));
+ size = sizeof(Tcl_HashEntry) + (count*sizeof(int)) - sizeof(hPtr->key);
+ if (size < sizeof(Tcl_HashEntry))
+ size = sizeof(Tcl_HashEntry);
+ hPtr = (Tcl_HashEntry *) ckalloc(size);
for (iPtr1 = array, iPtr2 = hPtr->key.words;
@@ -924,7 +927,10 @@
CONST char *string = (CONST char *) keyPtr;
Tcl_HashEntry *hPtr;
+ unsigned int size;
- hPtr = (Tcl_HashEntry *) ckalloc((unsigned)
- (sizeof(Tcl_HashEntry) + strlen(string) + 1 - sizeof(hPtr->key)));
+ size = sizeof(Tcl_HashEntry) + strlen(string) + 1 - sizeof(hPtr->key);
+ if (size < sizeof(Tcl_HashEntry))
+ size = sizeof(Tcl_HashEntry);
+ hPtr = (Tcl_HashEntry *) ckalloc(size);
strcpy(hPtr->key.string, string);