From a2a8c7a118d9d16746b07938a44025fa7cd840cd Mon Sep 17 00:00:00 2001 From: Bret Ambrose Date: Fri, 1 May 2020 13:08:01 -0700 Subject: [PATCH 1/3] Misc fixes --- source/hpack.c | 4 +--- source/http.c | 32 +++++++++++++++++++++----------- tests/proxy_test_helper.c | 2 +- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/source/hpack.c b/source/hpack.c index 239a4ffa6..7a0c0fc40 100644 --- a/source/hpack.c +++ b/source/hpack.c @@ -1261,9 +1261,7 @@ int aws_hpack_decode( goto handle_complete; } break; - default: { - AWS_ASSERT(0 && "invalid state"); - } break; + default: { AWS_ASSERT(0 && "invalid state"); } break; } } diff --git a/source/http.c b/source/http.c index 6cdaa3524..19a97d52a 100644 --- a/source/http.c +++ b/source/http.c @@ -22,12 +22,6 @@ #include -#ifdef _MSC_VER -# pragma warning(disable : 4311) /* 'type cast': pointer truncation from 'void *' to 'int' */ -#else -# pragma GCC diagnostic ignored "-Wpointer-to-int-cast" -#endif - #define AWS_DEFINE_ERROR_INFO_HTTP(CODE, STR) [(CODE)-0x0800] = AWS_DEFINE_ERROR_INFO(CODE, STR, "aws-c-http") /* clang-format off */ @@ -147,6 +141,16 @@ static struct aws_log_subject_info_list s_log_subject_list = { .count = AWS_ARRAY_SIZE(s_log_subject_infos), }; +struct aws_enum_value { + struct aws_allocator *allocator; + int value; +}; + +static void s_destroy_enum_value(void *value) { + struct aws_enum_value *enum_value = value; + aws_mem_release(enum_value->allocator, enum_value); +} + /** * Given array of aws_byte_cursors, init hashtable where... * Key is aws_byte_cursor* (pointing into cursor from array) and comparisons are case-insensitive. @@ -167,13 +171,18 @@ static void s_init_str_to_enum_hash_table( ignore_case ? aws_hash_byte_cursor_ptr_ignore_case : aws_hash_byte_cursor_ptr, (aws_hash_callback_eq_fn *)(ignore_case ? aws_byte_cursor_eq_ignore_case : aws_byte_cursor_eq), NULL, - NULL); + s_destroy_enum_value); AWS_FATAL_ASSERT(!err); for (size_t i = start_index; i < (size_t)end_index; ++i) { - int was_created; + int was_created = 0; + struct aws_enum_value *enum_value = aws_mem_calloc(alloc, 1, sizeof(struct aws_enum_value)); + AWS_FATAL_ASSERT(enum_value); + enum_value->allocator = alloc; + enum_value->value = i; + AWS_FATAL_ASSERT(str_array[i].ptr && "Missing enum string"); - err = aws_hash_table_put(table, &str_array[i], (void *)i, &was_created); + err = aws_hash_table_put(table, &str_array[i], (void *)enum_value, &was_created); AWS_FATAL_ASSERT(!err && was_created); } } @@ -186,7 +195,8 @@ static int s_find_in_str_to_enum_hash_table(const struct aws_hash_table *table, struct aws_hash_element *elem; aws_hash_table_find(table, key, &elem); if (elem) { - return (int)elem->value; + struct aws_enum_value *enum_value = elem->value; + return enum_value->value; } return -1; } @@ -235,7 +245,7 @@ static void s_versions_init(struct aws_allocator *alloc) { static void s_versions_clean_up(void) {} struct aws_byte_cursor aws_http_version_to_str(enum aws_http_version version) { - if (version < AWS_HTTP_VERSION_UNKNOWN || version >= AWS_HTTP_VERSION_COUNT) { + if ((int)version < AWS_HTTP_VERSION_UNKNOWN || (int)version >= AWS_HTTP_VERSION_COUNT) { version = AWS_HTTP_VERSION_UNKNOWN; } diff --git a/tests/proxy_test_helper.c b/tests/proxy_test_helper.c index 9dc5e51d3..345ccec96 100644 --- a/tests/proxy_test_helper.c +++ b/tests/proxy_test_helper.c @@ -340,4 +340,4 @@ int proxy_tester_verify_connection_attempt_was_to_proxy( ASSERT_TRUE(tester->connection_port == expected_port); return AWS_OP_SUCCESS; -} \ No newline at end of file +} From 5a4b18cb6af49f8d861bb0e6ec023bc082c61735 Mon Sep 17 00:00:00 2001 From: Bret Ambrose Date: Fri, 1 May 2020 14:02:55 -0700 Subject: [PATCH 2/3] Sigh --- source/http.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/http.c b/source/http.c index 19a97d52a..2ad5b4c8d 100644 --- a/source/http.c +++ b/source/http.c @@ -174,7 +174,7 @@ static void s_init_str_to_enum_hash_table( s_destroy_enum_value); AWS_FATAL_ASSERT(!err); - for (size_t i = start_index; i < (size_t)end_index; ++i) { + for (int i = start_index; i < end_index; ++i) { int was_created = 0; struct aws_enum_value *enum_value = aws_mem_calloc(alloc, 1, sizeof(struct aws_enum_value)); AWS_FATAL_ASSERT(enum_value); From c136aee09dc70483a7af1078a604877f6ee5b15b Mon Sep 17 00:00:00 2001 From: Bret Ambrose Date: Sun, 3 May 2020 08:04:55 -0700 Subject: [PATCH 3/3] Format weirdness --- source/hpack.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/hpack.c b/source/hpack.c index 7a0c0fc40..239a4ffa6 100644 --- a/source/hpack.c +++ b/source/hpack.c @@ -1261,7 +1261,9 @@ int aws_hpack_decode( goto handle_complete; } break; - default: { AWS_ASSERT(0 && "invalid state"); } break; + default: { + AWS_ASSERT(0 && "invalid state"); + } break; } }