From f2750d7b48da2ce98b6ce65dc4f967c8253f5acf Mon Sep 17 00:00:00 2001 From: Katherine Date: Wed, 27 Sep 2017 00:16:26 +0200 Subject: [PATCH] Skip to avoid numeric values of 0 for set items. (#72) Skip tests to avoid numeric values of 0 for set items. These are disallowed by the set API since it depends on returning `NULL` for errors. --- fuzz/fuzz_adt_set.c | 18 ++++++++++++++---- fuzz/type_info_adt_set.c | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/fuzz/fuzz_adt_set.c b/fuzz/fuzz_adt_set.c index 93df2fd5a..f7ddc11c4 100644 --- a/fuzz/fuzz_adt_set.c +++ b/fuzz/fuzz_adt_set.c @@ -28,6 +28,9 @@ cmp_item(const void *pa, const void *pb) uintptr_t a = (uintptr_t) pa; uintptr_t b = (uintptr_t) pb; + assert(pa != NULL); + assert(pb != NULL); + return a < b ? -1 : a > b ? 1 : 0; } @@ -134,8 +137,11 @@ theft_trial_res prop_set_equality(struct theft *t, void *arg1) set_b = set_create(cmp_item); for (i = 0; i < seq->count; i++) { - (void) set_add(&set_a, (void *) (uintptr_t) seq->values[i]); /* XXX */ - (void) set_add(&set_b, (void *) (uintptr_t) permuted[i]); + assert(seq->values[i] != 0); + assert(permuted[i] != 0); + + (void) set_add(&set_a, (void *) ((uintptr_t) seq->values[i])); /* XXX */ + (void) set_add(&set_b, (void *) ((uintptr_t) permuted[i])); } if (!set_equal(set_a, set_b)) { @@ -176,7 +182,9 @@ op_add(struct model *m, struct set_op *op, struct set **set) old_s = *set; - (void) set_add(set, (void *) op->u.add.item); /* XXX */ + assert(op->u.add.item != 0); + + (void) set_add(set, (void *) ((uintptr_t) op->u.add.item)); /* XXX */ if (m->env->verbosity > 0) { fprintf(stderr, "ITEM IS %zu (decimal)\n", (size_t) op->u.add.item); @@ -200,7 +208,9 @@ op_remove(struct model *m, struct set_op *op, struct set **set) old_s = *set; - set_remove(set, (void *) op->u.remove.item); + assert(op->u.remove.item != 0); + + set_remove(set, (void *) ((uintptr_t) op->u.remove.item)); if (m->env->verbosity > 0) { fprintf(stderr, "REMOVE 0x%" PRIxPTR " to %p => %p\n", diff --git a/fuzz/type_info_adt_set.c b/fuzz/type_info_adt_set.c index 4ea03ce94..e56563251 100644 --- a/fuzz/type_info_adt_set.c +++ b/fuzz/type_info_adt_set.c @@ -45,10 +45,16 @@ alloc_scen(struct theft *t, void *type_env, void **output) switch (op->t) { case SET_OP_ADD: op->u.add.item = theft_random_bits(t, env->item_bits); + if (op->u.add.item == 0) { + goto skip; + } break; case SET_OP_REMOVE: op->u.remove.item = theft_random_bits(t, env->item_bits); + if (op->u.remove.item == 0) { + goto skip; + } break; case SET_OP_CLEAR: @@ -63,6 +69,12 @@ alloc_scen(struct theft *t, void *type_env, void **output) *output = res; return THEFT_ALLOC_OK; + +skip: + + free(res); + + return THEFT_ALLOC_SKIP; } static void @@ -136,11 +148,20 @@ alloc_seq(struct theft *t, void *type_env, void **output) for (size_t i = 0; i < count; i++) { res->values[i] = theft_random_bits(t, 16); + if (res->values[i] == 0) { + goto skip; + } } *output = res; return THEFT_ALLOC_OK; + +skip: + + free(res); + + return THEFT_ALLOC_SKIP; } static void