From da438e276311514f144e116f815bfd39b9c28237 Mon Sep 17 00:00:00 2001 From: Zvonimir Date: Tue, 10 Nov 2020 16:00:05 -0700 Subject: [PATCH] Passing size of 0 to malloc leads to assertion violation This commit avoids the situation where size of 0 can be passed to malloc. I think it does not alter the spirit of the benchmark. --- c/aws-c-common/aws_string_eq_byte_buf_harness.i | 2 +- c/aws-c-common/aws_string_new_from_array_harness.i | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/c/aws-c-common/aws_string_eq_byte_buf_harness.i b/c/aws-c-common/aws_string_eq_byte_buf_harness.i index 2409f1fe18f..87ea7f60285 100644 --- a/c/aws-c-common/aws_string_eq_byte_buf_harness.i +++ b/c/aws-c-common/aws_string_eq_byte_buf_harness.i @@ -6860,7 +6860,7 @@ struct aws_string *ensure_string_is_allocated_nondet_length() { struct aws_string *ensure_string_is_allocated_bounded_length(size_t max_size) { size_t len = nondet_uint64_t(); - assume_abort_if_not(len < max_size); + assume_abort_if_not(0 < len && len < max_size); return ensure_string_is_allocated(len); } diff --git a/c/aws-c-common/aws_string_new_from_array_harness.i b/c/aws-c-common/aws_string_new_from_array_harness.i index 8e630861f92..20c602b1772 100644 --- a/c/aws-c-common/aws_string_new_from_array_harness.i +++ b/c/aws-c-common/aws_string_new_from_array_harness.i @@ -9460,10 +9460,11 @@ struct aws_string *aws_string_clone_or_reuse(struct aws_allocator *allocator, co } void aws_string_new_from_array_harness() { - size_t alloc_size; + size_t alloc_size = nondet_size_t(); + assume_abort_if_not(alloc_size > 0); uint8_t *array = bounded_malloc(alloc_size); struct aws_allocator *allocator = can_fail_allocator(); - size_t reported_size; + size_t reported_size = nondet_size_t(); assume_abort_if_not(reported_size <= alloc_size);