summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo van der Sanden <hv@crypt.org>2002-07-19 22:47:57 +0000
committerchip <chip@pobox.com>2002-07-19 22:47:57 +0000
commitc3d48d4eb69b179fda4abfde9f3f9d4e70175253 (patch)
tree760837873123fb4dc3c9c2a8259ec9113f0ebdcb
parentc15618675dfa13dd673bd6d471ddf2288512c9b4 (diff)
downloadperl-c3d48d4eb69b179fda4abfde9f3f9d4e70175253.tar.gz
ensure that hashes never attempt to malloc with a negative size
Subject: Re: [ID 20000421.002] Math::BigInt out of memory? p4raw-id: //depot/maint-5.005/perl@17647
-rw-r--r--hv.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/hv.c b/hv.c
index e0091eac23..414b5a86e4 100644
--- a/hv.c
+++ b/hv.c
@@ -25,7 +25,10 @@ static void more_he _((void));
# define ARRAY_ALLOC_BYTES(size) ( (size)*sizeof(HE*) )
#else
# define MALLOC_OVERHEAD 16
-# define ARRAY_ALLOC_BYTES(size) ( (size)*sizeof(HE*)*2 - MALLOC_OVERHEAD )
+# define ARRAY_ALLOC_BYTES(size) \
+ (((size) < 64) \
+ ? (size) * sizeof(HE*) \
+ : (size) * sizeof(HE*) * 2 - MALLOC_OVERHEAD)
#endif
STATIC HE*