diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2021-09-11 15:38:06 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2021-09-11 22:47:10 +0300 |
commit | deea7da6268185b12238399530a561938189d336 (patch) | |
tree | 31f1900eec7da86d67b1c663dc7d386b3d7e9fc2 /alloc.c | |
parent | dc98162d7e787e9af1ff99c07eef0b0280a44a7a (diff) | |
download | bdwgc-deea7da6268185b12238399530a561938189d336.tar.gz |
Ensure add_to_heap_inner arguments are valid (refactoring)
* alloc.c [GC_ASSERTIONS] (add_to_heap_inner): Declare i local
variable; iterate or section to check that there is no intersection
with the range given by the arguments.
* alloc.c (add_to_heap_inner): Add assertion that the arguments are
multiple of HBLKSIZE.
Diffstat (limited to 'alloc.c')
-rw-r--r-- | alloc.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -1348,7 +1348,13 @@ static void add_to_heap_inner(struct hblk *p, size_t bytes) { hdr * phdr; word endp; +# ifdef GC_ASSERTIONS + unsigned i; +# endif + GC_ASSERT((word)p % HBLKSIZE == 0); + GC_ASSERT(bytes % HBLKSIZE == 0); + GC_ASSERT(bytes > 0); GC_ASSERT(GC_all_nils != NULL); if (GC_n_heap_sects >= MAX_HEAP_SECTS) { ABORT("Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS"); @@ -1374,6 +1380,18 @@ static void add_to_heap_inner(struct hblk *p, size_t bytes) return; } GC_ASSERT(endp > (word)p && endp == (word)p + bytes); +# ifdef GC_ASSERTIONS + /* Ensure no intersection between sections. */ + for (i = 0; i < GC_n_heap_sects; i++) { + word hs_start = (word)GC_heap_sects[i].hs_start; + word hs_end = hs_start + GC_heap_sects[i].hs_bytes; + word p_e = (word)p + bytes; + + GC_ASSERT(!((hs_start <= (word)p && (word)p < hs_end) + || (hs_start < p_e && p_e <= hs_end) + || ((word)p < hs_start && hs_end < p_e))); + } +# endif GC_heap_sects[GC_n_heap_sects].hs_start = (ptr_t)p; GC_heap_sects[GC_n_heap_sects].hs_bytes = bytes; GC_n_heap_sects++; |