~ chicken-core (chicken-5) eccd1789742975c14030b25a5d4149163e9c0ec5


commit eccd1789742975c14030b25a5d4149163e9c0ec5
Author:     Peter Bex <peter.bex@xs4all.nl>
AuthorDate: Thu Oct 17 21:23:18 2013 +0200
Commit:     Moritz Heidkamp <moritz@twoticketsplease.de>
CommitDate: Wed Oct 23 11:40:32 2013 +0200

    Don't do a shady unsigned comparison, but ensure we're growing the heap before checking it grows enough to fit the stack
    
    Signed-off-by: Moritz Heidkamp <moritz@twoticketsplease.de>

diff --git a/runtime.c b/runtime.c
index 0ed18de2..41894761 100644
--- a/runtime.c
+++ b/runtime.c
@@ -3296,12 +3296,13 @@ C_regparm void C_fcall C_rereclaim2(C_uword size, int double_plus)
   if(size < MINIMAL_HEAP_SIZE) size = MINIMAL_HEAP_SIZE;
 
   /*
-   * Heap must at least grow enough to accommodate first generation
-   * (nursery).  Because we're calculating the total heap size here
-   * (fromspace *AND* tospace), we have to double the stack size,
-   * otherwise we'd accommodate only half the stack in the tospace.
+   * When heap grows, ensure it's enough to accommodate first
+   * generation (nursery).  Because we're calculating the total heap
+   * size here (fromspace *AND* tospace), we have to double the stack
+   * size, otherwise we'd accommodate only half the stack in the tospace.
    */
-  if(size - heap_size < stack_size * 2) size = heap_size + stack_size * 2;
+  if(size > heap_size && size - heap_size < stack_size * 2)
+    size = heap_size + stack_size * 2;
 	  
   if(size > C_maximal_heap_size) size = C_maximal_heap_size;
 
Trap