summaryrefslogtreecommitdiff
path: root/typd_mlc.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-06-14 07:51:03 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-06-14 07:51:03 +0300
commitef3462b717389a3429b35cc42c3b7424033baea1 (patch)
tree0f4d187e4ca64868a7baa7ee41866e9475dd709a /typd_mlc.c
parentdaa06b3acd21e01fa45f1114ed5a575994ea5898 (diff)
downloadbdwgc-ef3462b717389a3429b35cc42c3b7424033baea1.tar.gz
Assert that size of element of a typed object is non-zero
(refactoring) * typd_mlc.c (LeafDescriptor.size): Refine comment. * typd_mlc.c (GC_make_leaf_descriptor, GC_make_array_descriptor): Add assertion that size argument is non-zero. * typd_mlc.c (GC_push_complex_descriptor): Add assertion that sz local variable is non-zero (at least if nelements is non-zero).
Diffstat (limited to 'typd_mlc.c')
-rw-r--r--typd_mlc.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/typd_mlc.c b/typd_mlc.c
index 59643b72..efc90561 100644
--- a/typd_mlc.c
+++ b/typd_mlc.c
@@ -351,7 +351,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL
struct LeafDescriptor { /* Describes simple array. */
word ld_tag;
# define LEAF_TAG 1
- word ld_size; /* Bytes per element; */
+ word ld_size; /* Bytes per element; non-zero, */
/* multiple of ALIGNMENT. */
word ld_nelements; /* Number of elements. */
GC_descr ld_descriptor; /* A simple length, bitmap, */
@@ -384,6 +384,7 @@ STATIC complex_descriptor *GC_make_leaf_descriptor(word size, word nelements,
complex_descriptor *result = (complex_descriptor *)
GC_malloc_atomic(sizeof(struct LeafDescriptor));
+ GC_ASSERT(size != 0);
if (EXPECT(NULL == result, FALSE)) return NULL;
result -> ld.ld_tag = LEAF_TAG;
@@ -441,6 +442,7 @@ STATIC int GC_make_array_descriptor(size_t nelements, size_t size,
/* descriptors to speed up marking, and to reduce the amount */
/* of space needed on the mark stack. */
+ GC_ASSERT(size != 0);
if ((d & GC_DS_TAGS) == GC_DS_LENGTH) {
if (d == (GC_descr)size) {
*psimple_d = nelements * d; /* no overflow guaranteed by caller */
@@ -607,6 +609,7 @@ STATIC mse *GC_push_complex_descriptor(word *addr,
sz = complex_d -> ld.ld_size;
if (EXPECT(msl - msp <= (ptrdiff_t)nelements, FALSE)) return NULL;
+ GC_ASSERT(sz != 0);
for (i = 0; i < nelements; i++) {
msp++;
msp -> mse_start = current;
@@ -618,6 +621,7 @@ STATIC mse *GC_push_complex_descriptor(word *addr,
element_descr = complex_d -> ad.ad_element_descr;
nelements = complex_d -> ad.ad_nelements;
sz = GC_descr_obj_size(element_descr);
+ GC_ASSERT(sz != 0 || 0 == nelements);
for (i = 0; i < nelements; i++) {
msp = GC_push_complex_descriptor((word *)current, element_descr,
msp, msl);
@@ -630,6 +634,7 @@ STATIC mse *GC_push_complex_descriptor(word *addr,
msp = GC_push_complex_descriptor((word *)current,
complex_d -> sd.sd_first, msp, msl);
if (EXPECT(NULL == msp, FALSE)) return NULL;
+ GC_ASSERT(sz != 0);
current += sz;
msp = GC_push_complex_descriptor((word *)current,
complex_d -> sd.sd_second, msp, msl);