2222
2323#include <ctype.h>
2424
25- #ifdef _MSC_VER
26- # pragma warning(disable : 4311) /* 'type cast': pointer truncation from 'void *' to 'int' */
27- #else
28- # pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
29- #endif
30-
3125#define AWS_DEFINE_ERROR_INFO_HTTP (CODE , STR ) [(CODE)-0x0800] = AWS_DEFINE_ERROR_INFO(CODE, STR, "aws-c-http")
3226
3327/* clang-format off */
@@ -147,6 +141,16 @@ static struct aws_log_subject_info_list s_log_subject_list = {
147141 .count = AWS_ARRAY_SIZE (s_log_subject_infos ),
148142};
149143
144+ struct aws_enum_value {
145+ struct aws_allocator * allocator ;
146+ int value ;
147+ };
148+
149+ static void s_destroy_enum_value (void * value ) {
150+ struct aws_enum_value * enum_value = value ;
151+ aws_mem_release (enum_value -> allocator , enum_value );
152+ }
153+
150154/**
151155 * Given array of aws_byte_cursors, init hashtable where...
152156 * 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(
167171 ignore_case ? aws_hash_byte_cursor_ptr_ignore_case : aws_hash_byte_cursor_ptr ,
168172 (aws_hash_callback_eq_fn * )(ignore_case ? aws_byte_cursor_eq_ignore_case : aws_byte_cursor_eq ),
169173 NULL ,
170- NULL );
174+ s_destroy_enum_value );
171175 AWS_FATAL_ASSERT (!err );
172176
173- for (size_t i = start_index ; i < (size_t )end_index ; ++ i ) {
174- int was_created ;
177+ for (int i = start_index ; i < end_index ; ++ i ) {
178+ int was_created = 0 ;
179+ struct aws_enum_value * enum_value = aws_mem_calloc (alloc , 1 , sizeof (struct aws_enum_value ));
180+ AWS_FATAL_ASSERT (enum_value );
181+ enum_value -> allocator = alloc ;
182+ enum_value -> value = i ;
183+
175184 AWS_FATAL_ASSERT (str_array [i ].ptr && "Missing enum string" );
176- err = aws_hash_table_put (table , & str_array [i ], (void * )i , & was_created );
185+ err = aws_hash_table_put (table , & str_array [i ], (void * )enum_value , & was_created );
177186 AWS_FATAL_ASSERT (!err && was_created );
178187 }
179188}
@@ -186,7 +195,8 @@ static int s_find_in_str_to_enum_hash_table(const struct aws_hash_table *table,
186195 struct aws_hash_element * elem ;
187196 aws_hash_table_find (table , key , & elem );
188197 if (elem ) {
189- return (int )elem -> value ;
198+ struct aws_enum_value * enum_value = elem -> value ;
199+ return enum_value -> value ;
190200 }
191201 return -1 ;
192202}
@@ -235,7 +245,7 @@ static void s_versions_init(struct aws_allocator *alloc) {
235245static void s_versions_clean_up (void ) {}
236246
237247struct aws_byte_cursor aws_http_version_to_str (enum aws_http_version version ) {
238- if (version < AWS_HTTP_VERSION_UNKNOWN || version >= AWS_HTTP_VERSION_COUNT ) {
248+ if (( int ) version < AWS_HTTP_VERSION_UNKNOWN || ( int ) version >= AWS_HTTP_VERSION_COUNT ) {
239249 version = AWS_HTTP_VERSION_UNKNOWN ;
240250 }
241251
0 commit comments