From: Taylor R Campbell Date: Thu, 28 Apr 2011 05:37:04 +0000 (+0000) Subject: Check whether requested memory size fits in object datum. X-Git-Tag: 20110609-Gtk~16^2~6 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=b72742eeb2b1d1aa311f702696f197e09220b066;p=mit-scheme.git Check whether requested memory size fits in object datum. Do this before even trying to allocate the memory. --- diff --git a/src/microcode/memmag.c b/src/microcode/memmag.c index d656203cd..82f535e35 100644 --- a/src/microcode/memmag.c +++ b/src/microcode/memmag.c @@ -120,12 +120,16 @@ setup_memory (unsigned long heap_size, exit (1); } + /* Consistency check 2 */ + if ((stack_size + heap_size + constant_size) >= DATUM_MASK) + goto allocation_too_large; + /* Allocate */ ALLOCATE_HEAP_SPACE ((stack_size + heap_size + constant_size), memory_block_start, memory_block_end); - /* Consistency check 2 */ + /* Consistency check 3 */ if (memory_block_start == 0) { outf_fatal ("Not enough memory for this configuration.\n"); @@ -133,9 +137,10 @@ setup_memory (unsigned long heap_size, exit (1); } - /* Consistency check 3 */ + /* Consistency check 4 */ if ((ADDRESS_TO_DATUM (memory_block_end)) > DATUM_MASK) { + allocation_too_large: outf_fatal ("Requested allocation is too large.\n"); outf_fatal ("Try again with a smaller argument to '--heap'.\n"); outf_flush_fatal ();