From 8c67790de966a0d4b793d8110fc6cb2f2646edf8 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Thu, 29 May 2014 00:46:21 +0400 Subject: [PATCH] Fix 'Array subscript is above array bounds' GCC warning in GC_new_kind/proc * misc.c (GC_new_kind_inner, GC_new_proc_inner): Move ABORT call so that to be immediately followed by return (to workaround "array subscript is above array bounds" warning reported by MinGW GCC 4.5.2); do not increase elements count in case of overflow. --- misc.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/misc.c b/misc.c index 6490541e..f41384b2 100644 --- a/misc.c +++ b/misc.c @@ -1771,18 +1771,22 @@ GC_API void ** GC_CALL GC_new_free_list(void) GC_API unsigned GC_CALL GC_new_kind_inner(void **fl, GC_word descr, int adjust, int clear) { - unsigned result = GC_n_kinds++; - - if (GC_n_kinds > MAXOBJKINDS) ABORT("Too many kinds"); - GC_obj_kinds[result].ok_freelist = fl; - GC_obj_kinds[result].ok_reclaim_list = 0; - GC_obj_kinds[result].ok_descriptor = descr; - GC_obj_kinds[result].ok_relocate_descr = adjust; - GC_obj_kinds[result].ok_init = (GC_bool)clear; -# ifdef ENABLE_DISCLAIM + unsigned result = GC_n_kinds; + + if (result < MAXOBJKINDS) { + GC_n_kinds++; + GC_obj_kinds[result].ok_freelist = fl; + GC_obj_kinds[result].ok_reclaim_list = 0; + GC_obj_kinds[result].ok_descriptor = descr; + GC_obj_kinds[result].ok_relocate_descr = adjust; + GC_obj_kinds[result].ok_init = (GC_bool)clear; +# ifdef ENABLE_DISCLAIM GC_obj_kinds[result].ok_mark_unconditionally = FALSE; GC_obj_kinds[result].ok_disclaim_proc = 0; -# endif +# endif + } else { + ABORT("Too many kinds"); + } return result; } @@ -1799,10 +1803,14 @@ GC_API unsigned GC_CALL GC_new_kind(void **fl, GC_word descr, int adjust, GC_API unsigned GC_CALL GC_new_proc_inner(GC_mark_proc proc) { - unsigned result = GC_n_mark_procs++; + unsigned result = GC_n_mark_procs; - if (GC_n_mark_procs > MAX_MARK_PROCS) ABORT("Too many mark procedures"); - GC_mark_procs[result] = proc; + if (result < MAX_MARK_PROCS) { + GC_n_mark_procs++; + GC_mark_procs[result] = proc; + } else { + ABORT("Too many mark procedures"); + } return result; } -- 2.40.0