Hi all, While still chasing the bug(s?) found by Megane and Mario, I noticed another small mistake in the memory handling of the GC. This one could have actual consequences in practice. The out of memory check does a calculation which is compared to a maximum memory endpoint.
This calculation is repeated later to really set the heap size, but that second calculation includes an extra alignment. This alignment adds up to 7 more bytes, which means there's a situation where we *just* run out of memory, but the test won't flag it. I tried to simplify the code to avoid similar bugs if this code is changed in the future, by assigning first, then checking. It seems so obvious, I'm scared I missed something :) This ALSO doesn't fix any of the aforementioned bugs... Cheers, Peter -- http://sjamaan.ath.cx -- "The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music." -- Donald Knuth
>From a65daafeba56d8bc79fe2567bd3824d68784c1e4 Mon Sep 17 00:00:00 2001 From: Peter Bex <[email protected]> Date: Thu, 21 Jun 2012 20:43:43 +0200 Subject: [PATCH] Fix out-of-memory check so it includes alignment (and prevent future bugs by removing the code duplication) --- runtime.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime.c b/runtime.c index bf4e578..b0ccc85 100644 --- a/runtime.c +++ b/runtime.c @@ -3346,11 +3346,11 @@ C_regparm void C_fcall really_remark(C_word *x) n = C_header_size(p); bytes = (h & C_BYTEBLOCK_BIT) ? n : n * sizeof(C_word); - if(((C_byte *)p2 + bytes + sizeof(C_word)) > new_tospace_limit) { + new_tospace_top = ((C_byte *)p2 + C_align(bytes) + sizeof(C_word)); + if(new_tospace_top > new_tospace_limit) { panic(C_text("out of memory - heap full while resizing")); } - new_tospace_top = (C_byte *)p2 + C_align(bytes) + sizeof(C_word); *x = (C_word)p2; p2->header = h; assert(!is_fptr(h)); -- 1.7.9.1
_______________________________________________ Chicken-hackers mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/chicken-hackers
