ensure that hashes never attempt to malloc with a negative size
authorHugo van der Sanden <hv@crypt.org>
Fri, 19 Jul 2002 22:47:57 +0000 (22:47 +0000)
committerchip <chip@pobox.com>
Fri, 19 Jul 2002 22:47:57 +0000 (22:47 +0000)
Subject: Re: [ID 20000421.002] Math::BigInt out of memory?

p4raw-id: //depot/maint-5.005/perl@17647

hv.c

index e0091ea..414b5a8 100644 (file)
--- 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*