From f1b5105a8cd56d6ff46eee5eb26276e3fd92abbd Mon Sep 17 00:00:00 2001 From: Justin Boswell Date: Mon, 13 May 2019 14:30:37 -0700 Subject: [PATCH] assert() -> AWS_ASSERT() (#348) * assert() -> AWS_ASSERT() * Removed assert.h includes * rewrote resolve buffer reading to appease gcc --- .clang-tidy | 2 +- include/aws/common/array_list.h | 1 - include/aws/common/assert.inl | 1 + include/aws/common/atomics_msvc.inl | 5 +-- include/aws/common/common.h | 7 ++-- include/aws/common/linked_list.h | 13 +++--- include/aws/common/task_scheduler.h | 2 +- include/aws/testing/aws_test_harness.h | 3 +- source/array_list.c | 1 - source/byte_buf.c | 53 ++++++++++++------------- source/common.c | 2 +- source/date_time.c | 8 ++-- source/encoding.c | 23 +++++------ source/error.c | 9 ++--- source/lru_cache.c | 8 ++-- source/posix/system_info.c | 16 ++++---- source/posix/thread.c | 1 - source/priority_queue.c | 5 +-- source/task_scheduler.c | 22 +++++----- source/windows/thread.c | 2 - tests/fuzz/base64_encoding_transitive.c | 20 +++++----- tests/fuzz/hex_encoding_transitive.c | 20 +++++----- tests/task_scheduler_test.c | 2 +- 23 files changed, 104 insertions(+), 122 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index a2a53285f..77f96f244 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -9,6 +9,6 @@ CheckOptions: - key: google-runtime-int.TypeSufix value: '_t' - key: fuchsia-restrict-system-includes.Includes - value: '*,-stdint.h,-stdbool.h' + value: '*,-stdint.h,-stdbool.h,-assert.h' ... diff --git a/include/aws/common/array_list.h b/include/aws/common/array_list.h index 685e89486..b6e0a68b1 100644 --- a/include/aws/common/array_list.h +++ b/include/aws/common/array_list.h @@ -18,7 +18,6 @@ #include #include -#include #include #define AWS_ARRAY_LIST_DEBUG_FILL 0xDD diff --git a/include/aws/common/assert.inl b/include/aws/common/assert.inl index a1aaa58fd..c6435a70b 100644 --- a/include/aws/common/assert.inl +++ b/include/aws/common/assert.inl @@ -30,6 +30,7 @@ void aws_backtrace_print(FILE *fp, void *call_site_data); AWS_EXTERN_C_END #if defined(CBMC) +# include # define AWS_ASSERT(cond) assert(cond) #elif defined(DEBUG_BUILD) # define AWS_ASSERT(cond) \ diff --git a/include/aws/common/atomics_msvc.inl b/include/aws/common/atomics_msvc.inl index dea4d3331..c528caddd 100644 --- a/include/aws/common/atomics_msvc.inl +++ b/include/aws/common/atomics_msvc.inl @@ -17,7 +17,6 @@ #include #include -#include #include #include #include @@ -97,7 +96,7 @@ enum aws_atomic_mode_priv { aws_atomic_priv_load, aws_atomic_priv_store }; static inline void aws_atomic_priv_barrier_before(enum aws_memory_order order, enum aws_atomic_mode_priv mode) { aws_atomic_priv_check_order(order); - assert(mode != aws_atomic_priv_load || order != aws_memory_order_release); + AWS_ASSERT(mode != aws_atomic_priv_load || order != aws_memory_order_release); if (order == aws_memory_order_relaxed) { /* no barriers required for relaxed mode */ @@ -121,7 +120,7 @@ static inline void aws_atomic_priv_barrier_before(enum aws_memory_order order, e static inline void aws_atomic_priv_barrier_after(enum aws_memory_order order, enum aws_atomic_mode_priv mode) { aws_atomic_priv_check_order(order); - assert(mode != aws_atomic_priv_store || order != aws_memory_order_acquire); + AWS_ASSERT(mode != aws_atomic_priv_store || order != aws_memory_order_acquire); if (order == aws_memory_order_relaxed) { /* no barriers required for relaxed mode */ diff --git a/include/aws/common/common.h b/include/aws/common/common.h index b9661a315..5e4beef49 100644 --- a/include/aws/common/common.h +++ b/include/aws/common/common.h @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -119,12 +118,12 @@ */ #ifdef CBMC #define AWS_PRECONDITION(cond) __CPROVER_assume(cond) -#define AWS_POSTCONDITION(cond) assert(cond) +#define AWS_POSTCONDITION(cond) AWS_ASSERT(cond) #define AWS_MEM_IS_READABLE(base, len) __CPROVER_r_ok((base), (len)) #define AWS_MEM_IS_WRITABLE(base, len) __CPROVER_w_ok((base), (len)) #else -#define AWS_PRECONDITION(cond) assert(cond) -#define AWS_POSTCONDITION(cond) assert(cond) +#define AWS_PRECONDITION(cond) AWS_ASSERT(cond) +#define AWS_POSTCONDITION(cond) AWS_ASSERT(cond) /* the C runtime does not give a way to check these properties, * but we can at least check that the pointer is valid */ #define AWS_MEM_IS_READABLE(base, len) (((len) == 0) || (base)) diff --git a/include/aws/common/linked_list.h b/include/aws/common/linked_list.h index 38ecebc4d..c67cb38ca 100644 --- a/include/aws/common/linked_list.h +++ b/include/aws/common/linked_list.h @@ -18,7 +18,6 @@ #include -#include #include /** @@ -152,7 +151,7 @@ AWS_STATIC_IMPL void aws_linked_list_push_back(struct aws_linked_list *list, str * Returns the element in the back of the list. */ static struct aws_linked_list_node *aws_linked_list_back(const struct aws_linked_list *list) { - assert(!aws_linked_list_empty(list)); + AWS_ASSERT(!aws_linked_list_empty(list)); return list->tail.prev; } @@ -160,7 +159,7 @@ static struct aws_linked_list_node *aws_linked_list_back(const struct aws_linked * Returns the element in the back of the list and removes it */ AWS_STATIC_IMPL struct aws_linked_list_node *aws_linked_list_pop_back(struct aws_linked_list *list) { - assert(!aws_linked_list_empty(list)); + AWS_ASSERT(!aws_linked_list_empty(list)); struct aws_linked_list_node *back = aws_linked_list_back(list); aws_linked_list_remove(back); return back; @@ -177,7 +176,7 @@ AWS_STATIC_IMPL void aws_linked_list_push_front(struct aws_linked_list *list, st * Returns the element in the front of the list. */ AWS_STATIC_IMPL struct aws_linked_list_node *aws_linked_list_front(const struct aws_linked_list *list) { - assert(!aws_linked_list_empty(list)); + AWS_ASSERT(!aws_linked_list_empty(list)); return list->head.next; } @@ -185,15 +184,15 @@ AWS_STATIC_IMPL struct aws_linked_list_node *aws_linked_list_front(const struct * Returns the element in the front of the list and removes it */ AWS_STATIC_IMPL struct aws_linked_list_node *aws_linked_list_pop_front(struct aws_linked_list *list) { - assert(!aws_linked_list_empty(list)); + AWS_ASSERT(!aws_linked_list_empty(list)); struct aws_linked_list_node *front = aws_linked_list_front(list); aws_linked_list_remove(front); return front; } AWS_STATIC_IMPL void aws_linked_list_swap_contents(struct aws_linked_list *a, struct aws_linked_list *b) { - assert(a); - assert(b); + AWS_ASSERT(a); + AWS_ASSERT(b); struct aws_linked_list_node *a_first = a->head.next; struct aws_linked_list_node *a_last = a->tail.prev; diff --git a/include/aws/common/task_scheduler.h b/include/aws/common/task_scheduler.h index 185b7313e..ec1bb1565 100644 --- a/include/aws/common/task_scheduler.h +++ b/include/aws/common/task_scheduler.h @@ -52,7 +52,7 @@ AWS_STATIC_IMPL void aws_task_init(struct aws_task *task, aws_task_fn *fn, void } AWS_STATIC_IMPL void aws_task_run(struct aws_task *task, enum aws_task_status status) { - assert(task->fn); + AWS_ASSERT(task->fn); task->fn(task, task->arg, status); } diff --git a/include/aws/testing/aws_test_harness.h b/include/aws/testing/aws_test_harness.h index 02b518841..b0903f643 100644 --- a/include/aws/testing/aws_test_harness.h +++ b/include/aws/testing/aws_test_harness.h @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -364,7 +363,7 @@ static void s_print_stack_trace(int sig, siginfo_t *sig_info, void *user_data) { #endif static inline int s_aws_run_test_case(struct aws_test_harness *harness) { - assert(harness->run); + AWS_ASSERT(harness->run); #if defined(_WIN32) SetUnhandledExceptionFilter(s_test_print_stack_trace); diff --git a/source/array_list.c b/source/array_list.c index a89da1f1d..9a7a0dbec 100644 --- a/source/array_list.c +++ b/source/array_list.c @@ -15,7 +15,6 @@ #include -#include #include /* qsort */ int aws_array_list_shrink_to_fit(struct aws_array_list *AWS_RESTRICT list) { diff --git a/source/byte_buf.c b/source/byte_buf.c index 6d8eb3968..e375387ac 100644 --- a/source/byte_buf.c +++ b/source/byte_buf.c @@ -15,7 +15,6 @@ #include -#include #include #ifdef _MSC_VER @@ -101,22 +100,22 @@ void aws_byte_buf_clean_up_secure(struct aws_byte_buf *buf) { } bool aws_byte_buf_eq(const struct aws_byte_buf *a, const struct aws_byte_buf *b) { - assert(a && b); + AWS_ASSERT(a && b); return aws_array_eq(a->buffer, a->len, b->buffer, b->len); } bool aws_byte_buf_eq_ignore_case(const struct aws_byte_buf *a, const struct aws_byte_buf *b) { - assert(a && b); + AWS_ASSERT(a && b); return aws_array_eq_ignore_case(a->buffer, a->len, b->buffer, b->len); } bool aws_byte_buf_eq_c_str(const struct aws_byte_buf *buf, const char *c_str) { - assert(buf && c_str); + AWS_ASSERT(buf && c_str); return aws_array_eq_c_str(buf->buffer, buf->len, c_str); } bool aws_byte_buf_eq_c_str_ignore_case(const struct aws_byte_buf *buf, const char *c_str) { - assert(buf && c_str); + AWS_ASSERT(buf && c_str); return aws_array_eq_c_str_ignore_case(buf->buffer, buf->len, c_str); } @@ -200,9 +199,9 @@ int aws_byte_cursor_split_on_char_n( char split_on, size_t n, struct aws_array_list *AWS_RESTRICT output) { - assert(input_str && input_str->ptr); - assert(output); - assert(output->item_size >= sizeof(struct aws_byte_cursor)); + AWS_ASSERT(input_str && input_str->ptr); + AWS_ASSERT(output); + AWS_ASSERT(output->item_size >= sizeof(struct aws_byte_cursor)); size_t max_splits = n > 0 ? n : SIZE_MAX; size_t split_count = 0; @@ -236,7 +235,7 @@ int aws_byte_cursor_split_on_char( } int aws_byte_buf_cat(struct aws_byte_buf *dest, size_t number_of_args, ...) { - assert(dest); + AWS_ASSERT(dest); va_list ap; va_start(ap, number_of_args); @@ -256,12 +255,12 @@ int aws_byte_buf_cat(struct aws_byte_buf *dest, size_t number_of_args, ...) { } bool aws_byte_cursor_eq(const struct aws_byte_cursor *a, const struct aws_byte_cursor *b) { - assert(a && b); + AWS_ASSERT(a && b); return aws_array_eq(a->ptr, a->len, b->ptr, b->len); } bool aws_byte_cursor_eq_ignore_case(const struct aws_byte_cursor *a, const struct aws_byte_cursor *b) { - assert(a && b); + AWS_ASSERT(a && b); return aws_array_eq_ignore_case(a->ptr, a->len, b->ptr, b->len); } @@ -285,8 +284,8 @@ const uint8_t *aws_lookup_table_to_lower_get(void) { } bool aws_array_eq_ignore_case(const void *array_a, size_t len_a, const void *array_b, size_t len_b) { - assert(array_a || (len_a == 0)); - assert(array_b || (len_b == 0)); + AWS_ASSERT(array_a || (len_a == 0)); + AWS_ASSERT(array_b || (len_b == 0)); if (len_a != len_b) { return false; @@ -304,8 +303,8 @@ bool aws_array_eq_ignore_case(const void *array_a, size_t len_a, const void *arr } bool aws_array_eq(const void *array_a, size_t len_a, const void *array_b, size_t len_b) { - assert(array_a || (len_a == 0)); - assert(array_b || (len_b == 0)); + AWS_ASSERT(array_a || (len_a == 0)); + AWS_ASSERT(array_b || (len_b == 0)); if (len_a != len_b) { return false; @@ -319,8 +318,8 @@ bool aws_array_eq(const void *array_a, size_t len_a, const void *array_b, size_t } bool aws_array_eq_c_str_ignore_case(const void *array, size_t array_len, const char *c_str) { - assert(array || (array_len == 0)); - assert(c_str); + AWS_ASSERT(array || (array_len == 0)); + AWS_ASSERT(c_str); /* Simpler implementation could have been: * return aws_array_eq_ignore_case(array, array_len, c_str, strlen(c_str)); @@ -345,8 +344,8 @@ bool aws_array_eq_c_str_ignore_case(const void *array, size_t array_len, const c } bool aws_array_eq_c_str(const void *array, size_t array_len, const char *c_str) { - assert(array || (array_len == 0)); - assert(c_str); + AWS_ASSERT(array || (array_len == 0)); + AWS_ASSERT(c_str); /* Simpler implementation could have been: * return aws_array_eq(array, array_len, c_str, strlen(c_str)); @@ -393,22 +392,22 @@ uint64_t aws_hash_byte_cursor_ptr_ignore_case(const void *item) { } bool aws_byte_cursor_eq_byte_buf(const struct aws_byte_cursor *a, const struct aws_byte_buf *b) { - assert(a && b); + AWS_ASSERT(a && b); return aws_array_eq(a->ptr, a->len, b->buffer, b->len); } bool aws_byte_cursor_eq_byte_buf_ignore_case(const struct aws_byte_cursor *a, const struct aws_byte_buf *b) { - assert(a && b); + AWS_ASSERT(a && b); return aws_array_eq_ignore_case(a->ptr, a->len, b->buffer, b->len); } bool aws_byte_cursor_eq_c_str(const struct aws_byte_cursor *cursor, const char *c_str) { - assert(cursor && c_str); + AWS_ASSERT(cursor && c_str); return aws_array_eq_c_str(cursor->ptr, cursor->len, c_str); } bool aws_byte_cursor_eq_c_str_ignore_case(const struct aws_byte_cursor *cursor, const char *c_str) { - assert(cursor && c_str); + AWS_ASSERT(cursor && c_str); return aws_array_eq_c_str_ignore_case(cursor->ptr, cursor->len, c_str); } @@ -424,8 +423,8 @@ int aws_byte_buf_append(struct aws_byte_buf *to, const struct aws_byte_cursor *f if (from->len > 0) { /* This assert teaches clang-tidy that from->ptr and to->buffer cannot be null in a non-empty buffers */ - assert(from->ptr); - assert(to->buffer); + AWS_ASSERT(from->ptr); + AWS_ASSERT(to->buffer); memcpy(to->buffer + to->len, from->ptr, from->len); to->len += from->len; } @@ -544,8 +543,8 @@ int aws_byte_buf_append_dynamic(struct aws_byte_buf *to, const struct aws_byte_c } else { if (from->len > 0) { /* This assert teaches clang-tidy that from->ptr and to->buffer cannot be null in a non-empty buffers */ - assert(from->ptr); - assert(to->buffer); + AWS_ASSERT(from->ptr); + AWS_ASSERT(to->buffer); memcpy(to->buffer + to->len, from->ptr, from->len); } } diff --git a/source/common.c b/source/common.c index 07f6a9181..8b36dc4c1 100644 --- a/source/common.c +++ b/source/common.c @@ -225,7 +225,7 @@ static void *s_cf_allocator_reallocate(void *ptr, CFIndex new_size, CFOptionFlag (void)hint; struct aws_allocator *allocator = info; - assert(allocator->mem_realloc); + AWS_ASSERT(allocator->mem_realloc); void *original_allocation = (uint8_t *)ptr - sizeof(size_t); size_t original_size = 0; diff --git a/source/date_time.c b/source/date_time.c index 71cbbaf22..13ecf4b1d 100644 --- a/source/date_time.c +++ b/source/date_time.c @@ -676,7 +676,7 @@ int aws_date_time_to_local_time_str( const struct aws_date_time *dt, enum aws_date_format fmt, struct aws_byte_buf *output_buf) { - assert(fmt != AWS_DATE_FORMAT_AUTO_DETECT); + AWS_ASSERT(fmt != AWS_DATE_FORMAT_AUTO_DETECT); switch (fmt) { case AWS_DATE_FORMAT_RFC822: @@ -697,7 +697,7 @@ int aws_date_time_to_utc_time_str( const struct aws_date_time *dt, enum aws_date_format fmt, struct aws_byte_buf *output_buf) { - assert(fmt != AWS_DATE_FORMAT_AUTO_DETECT); + AWS_ASSERT(fmt != AWS_DATE_FORMAT_AUTO_DETECT); switch (fmt) { case AWS_DATE_FORMAT_RFC822: @@ -718,7 +718,7 @@ int aws_date_time_to_local_time_short_str( const struct aws_date_time *dt, enum aws_date_format fmt, struct aws_byte_buf *output_buf) { - assert(fmt != AWS_DATE_FORMAT_AUTO_DETECT); + AWS_ASSERT(fmt != AWS_DATE_FORMAT_AUTO_DETECT); switch (fmt) { case AWS_DATE_FORMAT_RFC822: @@ -739,7 +739,7 @@ int aws_date_time_to_utc_time_short_str( const struct aws_date_time *dt, enum aws_date_format fmt, struct aws_byte_buf *output_buf) { - assert(fmt != AWS_DATE_FORMAT_AUTO_DETECT); + AWS_ASSERT(fmt != AWS_DATE_FORMAT_AUTO_DETECT); switch (fmt) { case AWS_DATE_FORMAT_RFC822: diff --git a/source/encoding.c b/source/encoding.c index 03dfc2893..c48f77e09 100644 --- a/source/encoding.c +++ b/source/encoding.c @@ -15,7 +15,6 @@ #include -#include #include #include @@ -33,14 +32,14 @@ static inline size_t aws_common_private_base64_decode_sse41(const unsigned char (void)in; (void)out; (void)len; - assert(false); + AWS_ASSERT(false); return (size_t)-1; /* unreachable */ } static inline void aws_common_private_base64_encode_sse41(const unsigned char *in, unsigned char *out, size_t len) { (void)in; (void)out; (void)len; - assert(false); + AWS_ASSERT(false); } static inline bool aws_common_private_has_avx2(void) { return false; @@ -75,7 +74,7 @@ static const uint8_t BASE64_DECODING_TABLE[256] = { /* clang-format on */ int aws_hex_compute_encoded_len(size_t to_encode_len, size_t *encoded_length) { - assert(encoded_length); + AWS_ASSERT(encoded_length); size_t temp = (to_encode_len << 1) + 1; @@ -118,8 +117,8 @@ int aws_hex_encode(const struct aws_byte_cursor *AWS_RESTRICT to_encode, struct int aws_hex_encode_append_dynamic( const struct aws_byte_cursor *AWS_RESTRICT to_encode, struct aws_byte_buf *AWS_RESTRICT output) { - assert(to_encode->ptr); - assert(aws_byte_buf_is_valid(output)); + AWS_ASSERT(to_encode->ptr); + AWS_ASSERT(aws_byte_buf_is_valid(output)); size_t encoded_len = 0; if (AWS_UNLIKELY(aws_add_size_checked(to_encode->len, to_encode->len, &encoded_len))) { @@ -162,7 +161,7 @@ static int s_hex_decode_char_to_int(char character, uint8_t *int_val) { } int aws_hex_compute_decoded_len(size_t to_decode_len, size_t *decoded_len) { - assert(decoded_len); + AWS_ASSERT(decoded_len); size_t temp = (to_decode_len + 1); @@ -221,7 +220,7 @@ int aws_hex_decode(const struct aws_byte_cursor *AWS_RESTRICT to_decode, struct } int aws_base64_compute_encoded_len(size_t to_encode_len, size_t *encoded_len) { - assert(encoded_len); + AWS_ASSERT(encoded_len); size_t tmp = to_encode_len + 2; @@ -243,8 +242,8 @@ int aws_base64_compute_encoded_len(size_t to_encode_len, size_t *encoded_len) { } int aws_base64_compute_decoded_len(const struct aws_byte_cursor *AWS_RESTRICT to_decode, size_t *decoded_len) { - assert(to_decode); - assert(decoded_len); + AWS_ASSERT(to_decode); + AWS_ASSERT(decoded_len); const size_t len = to_decode->len; const uint8_t *input = to_decode->ptr; @@ -277,8 +276,8 @@ int aws_base64_compute_decoded_len(const struct aws_byte_cursor *AWS_RESTRICT to } int aws_base64_encode(const struct aws_byte_cursor *AWS_RESTRICT to_encode, struct aws_byte_buf *AWS_RESTRICT output) { - assert(to_encode->ptr); - assert(output->buffer); + AWS_ASSERT(to_encode->ptr); + AWS_ASSERT(output->buffer); size_t encoded_length = 0; if (AWS_UNLIKELY(aws_base64_compute_encoded_len(to_encode->len, &encoded_length))) { diff --git a/source/error.c b/source/error.c index c4168be88..a644f91ff 100644 --- a/source/error.c +++ b/source/error.c @@ -17,7 +17,6 @@ #include -#include #include #include @@ -146,15 +145,15 @@ void aws_register_error_info(const struct aws_error_info_list *error_info) { * - we'll either segfault immediately (for the first two) or for the count * assert, the registration will be ineffective. */ - assert(error_info); - assert(error_info->error_list); - assert(error_info->count); + AWS_ASSERT(error_info); + AWS_ASSERT(error_info->error_list); + AWS_ASSERT(error_info->count); int min_range = error_info->error_list[0].error_code; int slot_index = min_range >> SLOT_DIV_SHIFT; - assert(slot_index < AWS_MAX_ERROR_SLOTS && slot_index >= 0); + AWS_ASSERT(slot_index < AWS_MAX_ERROR_SLOTS && slot_index >= 0); if (slot_index >= AWS_MAX_ERROR_SLOTS || slot_index < 0) { /* This is an NDEBUG build apparently. Kill the process rather than diff --git a/source/lru_cache.c b/source/lru_cache.c index 7a98a28f4..3642a4f6f 100644 --- a/source/lru_cache.c +++ b/source/lru_cache.c @@ -14,8 +14,6 @@ */ #include -#include - struct cache_node { struct aws_linked_list_node node; struct aws_lru_cache *cache; @@ -42,8 +40,8 @@ int aws_lru_cache_init( aws_hash_callback_destroy_fn *destroy_key_fn, aws_hash_callback_destroy_fn *destroy_value_fn, size_t max_items) { - assert(allocator); - assert(max_items); + AWS_ASSERT(allocator); + AWS_ASSERT(max_items); cache->allocator = allocator; cache->max_items = max_items; @@ -115,7 +113,7 @@ int aws_lru_cache_put(struct aws_lru_cache *cache, const void *key, void *p_valu /* we're over the cache size limit. Remove whatever is in the back of * the list. */ struct aws_linked_list_node *node_to_remove = aws_linked_list_back(&cache->list); - assert(node_to_remove); + AWS_ASSERT(node_to_remove); struct cache_node *entry_to_remove = AWS_CONTAINER_OF(node_to_remove, struct cache_node, node); /*the callback will unlink and deallocate the node */ aws_hash_table_remove(&cache->table, entry_to_remove->key, NULL, NULL); diff --git a/source/posix/system_info.c b/source/posix/system_info.c index 374725afe..5996288c5 100644 --- a/source/posix/system_info.c +++ b/source/posix/system_info.c @@ -128,6 +128,7 @@ int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info * /* symbols look like: () [0x] * or: [0x] */ + (void)addr; const char *open_paren = strstr(symbol, "("); const char *close_paren = strstr(symbol, ")"); const char *exe_end = open_paren; @@ -149,7 +150,7 @@ int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info * } strncpy(frame->addr, addr_start, addr_end - addr_start); - long function_len = close_paren - open_paren - 1; + long function_len = (open_paren && close_paren) ? close_paren - open_paren - 1 : 0; if (function_len > 0) { /* dynamic symbol was found */ strncpy(frame->function, open_paren + 1, function_len); } @@ -197,13 +198,14 @@ void aws_backtrace_print(FILE *fp, void *call_site_data) { goto parse_failed; } char output[1024]; - fgets(output, sizeof(output), out); - pclose(out); - /* if addr2line or atos don't know what to do with an address, they just echo it */ - if (!strstr(output, " ")) { - goto parse_failed; + if (fgets(output, sizeof(output), out)) { + /* if addr2line or atos don't know what to do with an address, they just echo it */ + /* if there are spaces in the output, then they resolved something */ + if (strstr(output, " ")) { + symbol = output; + } } - symbol = output; + pclose(out); parse_failed: fprintf(fp, "%s%s", symbol, (symbol == symbols[frame_idx]) ? "\n" : ""); diff --git a/source/posix/thread.c b/source/posix/thread.c index b024d076f..c37dd36c9 100644 --- a/source/posix/thread.c +++ b/source/posix/thread.c @@ -17,7 +17,6 @@ #include -#include #include #include #include diff --git a/source/priority_queue.c b/source/priority_queue.c index 4685ff566..b3d50210b 100644 --- a/source/priority_queue.c +++ b/source/priority_queue.c @@ -15,7 +15,6 @@ #include -#include #include #define PARENT_OF(index) (((index)&1) ? (index) >> 1 : (index) > 1 ? ((index)-2) >> 1 : 0) @@ -27,8 +26,8 @@ static void s_swap(struct aws_priority_queue *queue, size_t a, size_t b) { /* Invariant: If the backpointer array is initialized, we have enough room for all elements */ if (queue->backpointers.data) { - assert(queue->backpointers.length > a); - assert(queue->backpointers.length > b); + AWS_ASSERT(queue->backpointers.length > a); + AWS_ASSERT(queue->backpointers.length > b); struct aws_priority_queue_node **bp_a = &((struct aws_priority_queue_node **)queue->backpointers.data)[a]; struct aws_priority_queue_node **bp_b = &((struct aws_priority_queue_node **)queue->backpointers.data)[b]; diff --git a/source/task_scheduler.c b/source/task_scheduler.c index 3b57aaad7..e3949cf32 100644 --- a/source/task_scheduler.c +++ b/source/task_scheduler.c @@ -15,8 +15,6 @@ #include -#include - static const size_t DEFAULT_QUEUE_SIZE = 7; static int s_compare_timestamps(const void *a, const void *b) { @@ -28,7 +26,7 @@ static int s_compare_timestamps(const void *a, const void *b) { static void s_run_all(struct aws_task_scheduler *scheduler, uint64_t current_time, enum aws_task_status status); int aws_task_scheduler_init(struct aws_task_scheduler *scheduler, struct aws_allocator *alloc) { - assert(alloc); + AWS_ASSERT(alloc); scheduler->alloc = alloc; aws_linked_list_init(&scheduler->timed_list); @@ -38,7 +36,7 @@ int aws_task_scheduler_init(struct aws_task_scheduler *scheduler, struct aws_all } void aws_task_scheduler_clean_up(struct aws_task_scheduler *scheduler) { - assert(scheduler); + AWS_ASSERT(scheduler); /* Execute all remaining tasks as CANCELED. * Do this in a loop so that tasks scheduled by other tasks are executed */ @@ -51,7 +49,7 @@ void aws_task_scheduler_clean_up(struct aws_task_scheduler *scheduler) { } bool aws_task_scheduler_has_tasks(const struct aws_task_scheduler *scheduler, uint64_t *next_task_time) { - assert(scheduler); + AWS_ASSERT(scheduler); uint64_t timestamp = UINT64_MAX; bool has_tasks = false; @@ -85,9 +83,9 @@ bool aws_task_scheduler_has_tasks(const struct aws_task_scheduler *scheduler, ui } void aws_task_scheduler_schedule_now(struct aws_task_scheduler *scheduler, struct aws_task *task) { - assert(scheduler); - assert(task); - assert(task->fn); + AWS_ASSERT(scheduler); + AWS_ASSERT(task); + AWS_ASSERT(task->fn); task->priority_queue_node.current_index = SIZE_MAX; aws_linked_list_node_reset(&task->node); @@ -101,9 +99,9 @@ void aws_task_scheduler_schedule_future( struct aws_task *task, uint64_t time_to_run) { - assert(scheduler); - assert(task); - assert(task->fn); + AWS_ASSERT(scheduler); + AWS_ASSERT(task); + AWS_ASSERT(task->fn); task->timestamp = time_to_run; @@ -128,7 +126,7 @@ void aws_task_scheduler_schedule_future( } void aws_task_scheduler_run_all(struct aws_task_scheduler *scheduler, uint64_t current_time) { - assert(scheduler); + AWS_ASSERT(scheduler); s_run_all(scheduler, current_time, AWS_TASK_STATUS_RUN_READY); } diff --git a/source/windows/thread.c b/source/windows/thread.c index fcbbee5c3..b2b60c02a 100644 --- a/source/windows/thread.c +++ b/source/windows/thread.c @@ -18,8 +18,6 @@ #include -#include - static struct aws_thread_options s_default_options = { /* zero will make sure whatever the default for that version of windows is used. */ .stack_size = 0, diff --git a/tests/fuzz/base64_encoding_transitive.c b/tests/fuzz/base64_encoding_transitive.c index 72755ec55..fe6b62f0a 100644 --- a/tests/fuzz/base64_encoding_transitive.c +++ b/tests/fuzz/base64_encoding_transitive.c @@ -15,8 +15,6 @@ #include -#include - /* NOLINTNEXTLINE(readability-identifier-naming) */ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { @@ -24,31 +22,31 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { size_t output_size = 0; int result = aws_base64_compute_encoded_len(size, &output_size); - assert(result == AWS_OP_SUCCESS); + AWS_ASSERT(result == AWS_OP_SUCCESS); struct aws_byte_cursor to_encode = aws_byte_cursor_from_array(data, size); struct aws_byte_buf encode_output; result = aws_byte_buf_init(&encode_output, allocator, output_size); - assert(result == AWS_OP_SUCCESS); + AWS_ASSERT(result == AWS_OP_SUCCESS); result = aws_base64_encode(&to_encode, &encode_output); - assert(result == AWS_OP_SUCCESS); + AWS_ASSERT(result == AWS_OP_SUCCESS); --encode_output.len; /* Remove null terminator */ struct aws_byte_cursor to_decode = aws_byte_cursor_from_buf(&encode_output); result = aws_base64_compute_decoded_len(&to_decode, &output_size); - assert(result == AWS_OP_SUCCESS); - assert(output_size == size); + AWS_ASSERT(result == AWS_OP_SUCCESS); + AWS_ASSERT(output_size == size); struct aws_byte_buf decode_output; result = aws_byte_buf_init(&decode_output, allocator, output_size); - assert(result == AWS_OP_SUCCESS); + AWS_ASSERT(result == AWS_OP_SUCCESS); result = aws_base64_decode(&to_decode, &decode_output); - assert(result == AWS_OP_SUCCESS); - assert(output_size == decode_output.len); - assert(memcmp(decode_output.buffer, data, size) == 0); + AWS_ASSERT(result == AWS_OP_SUCCESS); + AWS_ASSERT(output_size == decode_output.len); + AWS_ASSERT(memcmp(decode_output.buffer, data, size) == 0); aws_byte_buf_clean_up(&encode_output); aws_byte_buf_clean_up(&decode_output); diff --git a/tests/fuzz/hex_encoding_transitive.c b/tests/fuzz/hex_encoding_transitive.c index a591e3b6c..8f928665f 100644 --- a/tests/fuzz/hex_encoding_transitive.c +++ b/tests/fuzz/hex_encoding_transitive.c @@ -15,8 +15,6 @@ #include -#include - /* NOLINTNEXTLINE(readability-identifier-naming) */ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { @@ -24,31 +22,31 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { size_t output_size = 0; int result = aws_hex_compute_encoded_len(size, &output_size); - assert(result == AWS_OP_SUCCESS); + AWS_ASSERT(result == AWS_OP_SUCCESS); struct aws_byte_cursor to_encode = aws_byte_cursor_from_array(data, size); struct aws_byte_buf encode_output; result = aws_byte_buf_init(&encode_output, allocator, output_size); - assert(result == AWS_OP_SUCCESS); + AWS_ASSERT(result == AWS_OP_SUCCESS); result = aws_hex_encode(&to_encode, &encode_output); - assert(result == AWS_OP_SUCCESS); + AWS_ASSERT(result == AWS_OP_SUCCESS); --encode_output.len; /* Remove null terminator */ result = aws_hex_compute_decoded_len(encode_output.len, &output_size); - assert(result == AWS_OP_SUCCESS); - assert(output_size == size); + AWS_ASSERT(result == AWS_OP_SUCCESS); + AWS_ASSERT(output_size == size); struct aws_byte_buf decode_output; result = aws_byte_buf_init(&decode_output, allocator, output_size); - assert(result == AWS_OP_SUCCESS); + AWS_ASSERT(result == AWS_OP_SUCCESS); struct aws_byte_cursor decode_input = aws_byte_cursor_from_buf(&encode_output); result = aws_hex_decode(&decode_input, &decode_output); - assert(result == AWS_OP_SUCCESS); - assert(output_size == decode_output.len); - assert(memcmp(decode_output.buffer, data, size) == 0); + AWS_ASSERT(result == AWS_OP_SUCCESS); + AWS_ASSERT(output_size == decode_output.len); + AWS_ASSERT(memcmp(decode_output.buffer, data, size) == 0); aws_byte_buf_clean_up(&encode_output); aws_byte_buf_clean_up(&decode_output); diff --git a/tests/task_scheduler_test.c b/tests/task_scheduler_test.c index 61ea6c9fb..e5c51eb30 100644 --- a/tests/task_scheduler_test.c +++ b/tests/task_scheduler_test.c @@ -30,7 +30,7 @@ static size_t s_executed_tasks_n; /* Updates tl_executed_tasks and tl_executed_task_n when function is executed */ static void s_task_n_fn(struct aws_task *task, void *arg, enum aws_task_status status) { if (s_executed_tasks_n > AWS_ARRAY_SIZE(s_executed_tasks)) { - assert(0); + AWS_ASSERT(0); } struct executed_task_data *data = &s_executed_tasks[s_executed_tasks_n++];