LCOV - code coverage report
Current view: top level - seahorn/lib - fuzz_array_list_helper.c (source / functions) Hit Total Coverage
Test: all_fuzz.info Lines: 23 31 74.2 %
Date: 2021-04-23 16:28:21 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /*
       2             :  * aws_array_list helpers but for fuzzing
       3             :  */
       4             : 
       5             : #include <array_list_helper.h>
       6             : #include <aws/common/array_list.h>
       7             : #include <aws/common/common.h>
       8             : #include <bounds.h>
       9             : #include <limits.h>
      10             : #include <nondet.h>
      11             : #include <proof_allocators.h>
      12             : #include <seahorn/seahorn.h>
      13             : #include <stdint.h>
      14             : #include <stdlib.h>
      15             : 
      16           0 : void initialize_array_list(struct aws_array_list *const list) {
      17           0 :   list->current_size = nd_size_t();
      18           0 :   list->length = nd_size_t();
      19           0 :   list->item_size = nd_size_t();
      20           0 :   /// XXX Cannot do this for now
      21           0 :   list->data = can_fail_malloc(list->current_size);
      22           0 :   list->alloc = sea_allocator();
      23           0 : }
      24             : 
      25     4769591 : void initialize_bounded_array_list(struct aws_array_list *const list) {
      26     4769591 :   size_t max_item_size = fuzz_max_array_list_item_size();
      27     4769591 :   size_t max_initial_item_allocation = fuzz_max_array_list_len();
      28     4769591 : 
      29     4769591 :   /* item_size <= max_item_size */
      30     4769591 :   list->item_size = nd_size_t();
      31     4769591 :   list->item_size %= max_item_size;
      32     4769591 :   list->item_size = (list->item_size == 0) ? 1 : list->item_size;
      33     4769591 :   /* length <= max_initial_item_allocation */
      34     4769591 :   list->length = nd_size_t();
      35     4769591 :   list->length %= max_initial_item_allocation;
      36     4769591 :   // list->length = (list->length == 0) ? 1 : list->length;
      37     4769591 : 
      38     4769591 :   list->current_size = list->item_size * list->length;
      39     4769591 : 
      40     4769591 :   list->data = (list->current_size == 0) ? NULL : can_fail_malloc(list->current_size);
      41     4769591 :   list->alloc = sea_allocator();
      42     4769591 : }
      43             : 
      44             : bool aws_array_list_is_bounded(const struct aws_array_list *const list,
      45             :                                const size_t max_initial_item_allocation,
      46     1048358 :                                const size_t max_item_size) {
      47     1048358 :   bool item_size_is_bounded = list->item_size <= max_item_size;
      48     1048358 :   bool length_is_bounded = list->length <= max_initial_item_allocation;
      49     1048358 :   return item_size_is_bounded && length_is_bounded;
      50     1048358 : }

Generated by: LCOV version 1.13