summaryrefslogtreecommitdiffstats
path: root/kjs/collector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kjs/collector.cpp')
-rw-r--r--kjs/collector.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/kjs/collector.cpp b/kjs/collector.cpp
index 62d594329..b8d233850 100644
--- a/kjs/collector.cpp
+++ b/kjs/collector.cpp
@@ -23,6 +23,7 @@
#include "value.h"
#include "internal.h"
+#include <limits.h>
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
@@ -119,6 +120,9 @@ void* Collector::allocate(size_t s)
// didn't find one, need to allocate a new block
if (heap.usedBlocks == heap.numBlocks) {
+ static const size_t maxNumBlocks = ULONG_MAX / sizeof(CollectorBlock*) / GROWTH_FACTOR;
+ if (heap.numBlocks > maxNumBlocks)
+ return 0L;
heap.numBlocks = MAX(MIN_ARRAY_SIZE, heap.numBlocks * GROWTH_FACTOR);
heap.blocks = (CollectorBlock **)realloc(heap.blocks, heap.numBlocks * sizeof(CollectorBlock *));
}