summaryrefslogtreecommitdiffstats
path: root/generic/tclAlloc.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2009-09-29 05:03:46 (GMT)
committerdgp <dgp@users.sourceforge.net>2009-09-29 05:03:46 (GMT)
commit1d9466df83ad7999d5e606e39121eb3dd68b737f (patch)
treedb950a0e96ba25eff12acf38eb8a9aa06ee10edb /generic/tclAlloc.c
parent9ed15c4edf59c0dda55797c0debad69464c092c0 (diff)
downloadtcl-1d9466df83ad7999d5e606e39121eb3dd68b737f.zip
tcl-1d9466df83ad7999d5e606e39121eb3dd68b737f.tar.gz
tcl-1d9466df83ad7999d5e606e39121eb3dd68b737f.tar.bz2
* generic/tclAlloc.c: Cleaned up various routines in the
* generic/tclCkalloc.c: call stacks for memory allocation to * generic/tclInt.h: guarantee that any size values computed * generic/tclThreadAlloc.c: are within the domains of the routines they get passed to. [Bugs 2557696 and 2557796].
Diffstat (limited to 'generic/tclAlloc.c')
-rw-r--r--generic/tclAlloc.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/generic/tclAlloc.c b/generic/tclAlloc.c
index de21c7c..04627a6 100644
--- a/generic/tclAlloc.c
+++ b/generic/tclAlloc.c
@@ -15,7 +15,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclAlloc.c,v 1.27 2007/12/17 15:28:27 msofer Exp $
+ * RCS: @(#) $Id: tclAlloc.c,v 1.28 2009/09/29 05:03:46 dgp Exp $
*/
/*
@@ -265,7 +265,7 @@ TclpAlloc(
register union overhead *overPtr;
register long bucket;
register unsigned amount;
- struct block *bigBlockPtr;
+ struct block *bigBlockPtr = NULL;
if (!allocInit) {
/*
@@ -281,9 +281,11 @@ TclpAlloc(
* First the simple case: we simple allocate big blocks directly.
*/
- if (numBytes + OVERHEAD >= MAXMALLOC) {
- bigBlockPtr = (struct block *) TclpSysAlloc((unsigned)
- (sizeof(struct block) + OVERHEAD + numBytes), 0);
+ if (numBytes >= MAXMALLOC - OVERHEAD) {
+ if (numBytes <= UINT_MAX - OVERHEAD -sizeof(struct block)) {
+ bigBlockPtr = (struct block *) TclpSysAlloc((unsigned)
+ (sizeof(struct block) + OVERHEAD + numBytes), 0);
+ }
if (bigBlockPtr == NULL) {
Tcl_MutexUnlock(allocMutexPtr);
return NULL;