Workaround 'index out of bounds' UBSan false warning in push_marked
authorIvan Maidanski <ivmai@mail.ru>
Fri, 9 Dec 2016 23:07:25 +0000 (02:07 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 9 Dec 2016 23:07:25 +0000 (02:07 +0300)
* mark.c (GC_push_marked): Cast (h+1)->hb_body to word before
subtraction of sz value (and cast the result back to ptr_t).
* mark.c [ENABLE_DISCLAIM] (GC_push_unconditionally): Likewise.

mark.c

diff --git a/mark.c b/mark.c
index 8b776f5..167fa5a 100644 (file)
--- a/mark.c
+++ b/mark.c
@@ -1797,7 +1797,7 @@ STATIC void GC_push_marked(struct hblk *h, hdr *hhdr)
     if (sz > MAXOBJBYTES) {
         lim = h -> hb_body;
     } else {
-        lim = (h + 1)->hb_body - sz;
+        lim = (ptr_t)((word)(h + 1)->hb_body - sz);
     }
 
     switch(BYTES_TO_GRANULES(sz)) {
@@ -1856,7 +1856,7 @@ STATIC void GC_push_marked(struct hblk *h, hdr *hhdr)
     if (sz > MAXOBJBYTES)
         lim = h -> hb_body;
     else
-        lim = (h + 1)->hb_body - sz;
+        lim = (ptr_t)((word)(h + 1)->hb_body - sz);
 
     GC_mark_stack_top_reg = GC_mark_stack_top;
     for (p = h -> hb_body; (word)p <= (word)lim; p += sz)