summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2014-05-29 00:46:21 +0400
committerIvan Maidanski <ivmai@mail.ru>2014-05-29 00:46:21 +0400
commit8c67790de966a0d4b793d8110fc6cb2f2646edf8 (patch)
treeab4857e177fa4cbdb602e9e9ea66dc3e390b9f05 /misc.c
parentd5e4a978a85c4f468cbe9e0a5f660259e5d88516 (diff)
downloadbdwgc-8c67790de966a0d4b793d8110fc6cb2f2646edf8.tar.gz
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.
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c34
1 files 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;
}