summaryrefslogtreecommitdiffstats
path: root/generic/tclHash.c
diff options
context:
space:
mode:
authornijtmans <nijtmans@noemail.net>2010-12-10 21:59:22 (GMT)
committernijtmans <nijtmans@noemail.net>2010-12-10 21:59:22 (GMT)
commit6611242d2576ae12ed7693024aa5cf6da1bc5926 (patch)
treef5a596654db0ccc6fc206c51f688b6bd218ce97a /generic/tclHash.c
parentd6108b63f17b35327ea08d36a34681efec79bad5 (diff)
downloadtcl-6611242d2576ae12ed7693024aa5cf6da1bc5926.zip
tcl-6611242d2576ae12ed7693024aa5cf6da1bc5926.tar.gz
tcl-6611242d2576ae12ed7693024aa5cf6da1bc5926.tar.bz2
[Bug 3129448]: Possible over-allocation on 64-bit platforms, part 2
FossilOrigin-Name: e6ddd08613c8541a6cf7140ee21f67cef0244520
Diffstat (limited to 'generic/tclHash.c')
-rw-r--r--generic/tclHash.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/generic/tclHash.c b/generic/tclHash.c
index e778104..c7a550f 100644
--- a/generic/tclHash.c
+++ b/generic/tclHash.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclHash.c,v 1.47 2010/12/01 09:58:52 nijtmans Exp $
+ * RCS: @(#) $Id: tclHash.c,v 1.48 2010/12/10 21:59:23 nijtmans Exp $
*/
#include "tclInt.h"
@@ -829,14 +829,14 @@ AllocStringEntry(
{
const char *string = (const char *) keyPtr;
Tcl_HashEntry *hPtr;
- unsigned int size;
+ unsigned int size, allocsize;
- size = sizeof(Tcl_HashEntry) + strlen(string) + 1 - sizeof(hPtr->key);
- if (size < sizeof(Tcl_HashEntry)) {
- size = sizeof(Tcl_HashEntry);
+ allocsize = size = strlen(string) + 1;
+ if (size < sizeof(hPtr->key)) {
+ allocsize = sizeof(hPtr->key);
}
- hPtr = (Tcl_HashEntry *) ckalloc(size);
- strcpy(hPtr->key.string, string);
+ hPtr = (Tcl_HashEntry *) ckalloc(TclOffset(Tcl_HashEntry, key) + allocsize);
+ memcpy(hPtr->key.string, string, size);
hPtr->clientData = 0;
return hPtr;
}