From 807c368eb5e85fc671646e5f09cbbf3c068784dd Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 12 Feb 2024 15:31:08 -0800 Subject: [PATCH 1/8] Fix useless-cast warning --- include/aws/common/array_list.inl | 2 +- include/aws/common/math.inl | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/aws/common/array_list.inl b/include/aws/common/array_list.inl index 42f447e92..5472104c6 100644 --- a/include/aws/common/array_list.inl +++ b/include/aws/common/array_list.inl @@ -123,7 +123,7 @@ AWS_STATIC_IMPL void aws_array_list_clean_up_secure(struct aws_array_list *AWS_RESTRICT list) { AWS_PRECONDITION(AWS_IS_ZEROED(*list) || aws_array_list_is_valid(list)); if (list->alloc && list->data) { - aws_secure_zero((void *)list->data, list->current_size); + aws_secure_zero(list->data, list->current_size); aws_mem_release(list->alloc, list->data); } diff --git a/include/aws/common/math.inl b/include/aws/common/math.inl index 2081fbcca..ba7f09fde 100644 --- a/include/aws/common/math.inl +++ b/include/aws/common/math.inl @@ -86,7 +86,10 @@ AWS_STATIC_IMPL size_t aws_mul_size_saturating(size_t a, size_t b) { #if SIZE_BITS == 32 return (size_t)aws_mul_u32_saturating(a, b); #elif SIZE_BITS == 64 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wuseless-cast" return (size_t)aws_mul_u64_saturating(a, b); +# pragma GCC diagnostic pop #else # error "Target not supported" #endif @@ -100,7 +103,10 @@ AWS_STATIC_IMPL int aws_mul_size_checked(size_t a, size_t b, size_t *r) { #if SIZE_BITS == 32 return aws_mul_u32_checked(a, b, (uint32_t *)r); #elif SIZE_BITS == 64 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wuseless-cast" return aws_mul_u64_checked(a, b, (uint64_t *)r); +# pragma GCC diagnostic pop #else # error "Target not supported" #endif @@ -113,7 +119,10 @@ AWS_STATIC_IMPL size_t aws_add_size_saturating(size_t a, size_t b) { #if SIZE_BITS == 32 return (size_t)aws_add_u32_saturating(a, b); #elif SIZE_BITS == 64 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wuseless-cast" return (size_t)aws_add_u64_saturating(a, b); +# pragma GCC diagnostic pop #else # error "Target not supported" #endif @@ -127,7 +136,10 @@ AWS_STATIC_IMPL int aws_add_size_checked(size_t a, size_t b, size_t *r) { #if SIZE_BITS == 32 return aws_add_u32_checked(a, b, (uint32_t *)r); #elif SIZE_BITS == 64 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wuseless-cast" return aws_add_u64_checked(a, b, (uint64_t *)r); +# pragma GCC diagnostic pop #else # error "Target not supported" #endif @@ -137,7 +149,10 @@ AWS_STATIC_IMPL size_t aws_sub_size_saturating(size_t a, size_t b) { #if SIZE_BITS == 32 return (size_t)aws_sub_u32_saturating(a, b); #elif SIZE_BITS == 64 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wuseless-cast" return (size_t)aws_sub_u64_saturating(a, b); +# pragma GCC diagnostic pop #else # error "Target not supported" #endif @@ -147,7 +162,10 @@ AWS_STATIC_IMPL int aws_sub_size_checked(size_t a, size_t b, size_t *r) { #if SIZE_BITS == 32 return aws_sub_u32_checked(a, b, (uint32_t *)r); #elif SIZE_BITS == 64 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wuseless-cast" return aws_sub_u64_checked(a, b, (uint64_t *)r); +# pragma GCC diagnostic pop #else # error "Target not supported" #endif From e649f4e648a7b187fca10f4f1d4a1073adba7a0f Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 12 Feb 2024 15:43:24 -0800 Subject: [PATCH 2/8] ignore at file level --- include/aws/common/math.inl | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/include/aws/common/math.inl b/include/aws/common/math.inl index ba7f09fde..13c49e8e2 100644 --- a/include/aws/common/math.inl +++ b/include/aws/common/math.inl @@ -53,6 +53,11 @@ AWS_EXTERN_C_BEGIN # pragma warning(disable : 4127) /*Disable "conditional expression is constant" */ #endif /* _MSC_VER */ +#ifdef __cplusplus +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wuseless-cast" +#endif + AWS_STATIC_IMPL uint64_t aws_sub_u64_saturating(uint64_t a, uint64_t b) { return a <= b ? 0 : a - b; } @@ -86,10 +91,7 @@ AWS_STATIC_IMPL size_t aws_mul_size_saturating(size_t a, size_t b) { #if SIZE_BITS == 32 return (size_t)aws_mul_u32_saturating(a, b); #elif SIZE_BITS == 64 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wuseless-cast" return (size_t)aws_mul_u64_saturating(a, b); -# pragma GCC diagnostic pop #else # error "Target not supported" #endif @@ -103,10 +105,7 @@ AWS_STATIC_IMPL int aws_mul_size_checked(size_t a, size_t b, size_t *r) { #if SIZE_BITS == 32 return aws_mul_u32_checked(a, b, (uint32_t *)r); #elif SIZE_BITS == 64 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wuseless-cast" return aws_mul_u64_checked(a, b, (uint64_t *)r); -# pragma GCC diagnostic pop #else # error "Target not supported" #endif @@ -119,10 +118,7 @@ AWS_STATIC_IMPL size_t aws_add_size_saturating(size_t a, size_t b) { #if SIZE_BITS == 32 return (size_t)aws_add_u32_saturating(a, b); #elif SIZE_BITS == 64 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wuseless-cast" return (size_t)aws_add_u64_saturating(a, b); -# pragma GCC diagnostic pop #else # error "Target not supported" #endif @@ -136,10 +132,7 @@ AWS_STATIC_IMPL int aws_add_size_checked(size_t a, size_t b, size_t *r) { #if SIZE_BITS == 32 return aws_add_u32_checked(a, b, (uint32_t *)r); #elif SIZE_BITS == 64 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wuseless-cast" return aws_add_u64_checked(a, b, (uint64_t *)r); -# pragma GCC diagnostic pop #else # error "Target not supported" #endif @@ -149,10 +142,7 @@ AWS_STATIC_IMPL size_t aws_sub_size_saturating(size_t a, size_t b) { #if SIZE_BITS == 32 return (size_t)aws_sub_u32_saturating(a, b); #elif SIZE_BITS == 64 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wuseless-cast" return (size_t)aws_sub_u64_saturating(a, b); -# pragma GCC diagnostic pop #else # error "Target not supported" #endif @@ -162,10 +152,7 @@ AWS_STATIC_IMPL int aws_sub_size_checked(size_t a, size_t b, size_t *r) { #if SIZE_BITS == 32 return aws_sub_u32_checked(a, b, (uint32_t *)r); #elif SIZE_BITS == 64 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wuseless-cast" return aws_sub_u64_checked(a, b, (uint64_t *)r); -# pragma GCC diagnostic pop #else # error "Target not supported" #endif From a05291a5e10a141ed2c75b816d3ca347025a60f1 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 12 Feb 2024 15:46:30 -0800 Subject: [PATCH 3/8] Try only for gnuc --- include/aws/common/math.inl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/aws/common/math.inl b/include/aws/common/math.inl index 13c49e8e2..900f69d24 100644 --- a/include/aws/common/math.inl +++ b/include/aws/common/math.inl @@ -54,8 +54,10 @@ AWS_EXTERN_C_BEGIN #endif /* _MSC_VER */ #ifdef __cplusplus -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wuseless-cast" +# if defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wuseless-cast" +# endif #endif AWS_STATIC_IMPL uint64_t aws_sub_u64_saturating(uint64_t a, uint64_t b) { From 6bc7e8084cfe8bdb44f524c6c642c5dbd54cd81a Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Tue, 30 Jul 2024 09:59:06 -0700 Subject: [PATCH 4/8] can I just remove the cast? --- include/aws/common/math.inl | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/include/aws/common/math.inl b/include/aws/common/math.inl index 900f69d24..0907dc28b 100644 --- a/include/aws/common/math.inl +++ b/include/aws/common/math.inl @@ -53,13 +53,6 @@ AWS_EXTERN_C_BEGIN # pragma warning(disable : 4127) /*Disable "conditional expression is constant" */ #endif /* _MSC_VER */ -#ifdef __cplusplus -# if defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wuseless-cast" -# endif -#endif - AWS_STATIC_IMPL uint64_t aws_sub_u64_saturating(uint64_t a, uint64_t b) { return a <= b ? 0 : a - b; } @@ -93,7 +86,7 @@ AWS_STATIC_IMPL size_t aws_mul_size_saturating(size_t a, size_t b) { #if SIZE_BITS == 32 return (size_t)aws_mul_u32_saturating(a, b); #elif SIZE_BITS == 64 - return (size_t)aws_mul_u64_saturating(a, b); + return aws_mul_u64_saturating(a, b); #else # error "Target not supported" #endif From 29d7ca381d8258ba30151f36792ca591ee20d24d Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Tue, 30 Jul 2024 10:09:32 -0700 Subject: [PATCH 5/8] remove converstion --- include/aws/common/math.inl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/aws/common/math.inl b/include/aws/common/math.inl index 0907dc28b..07167528a 100644 --- a/include/aws/common/math.inl +++ b/include/aws/common/math.inl @@ -84,7 +84,7 @@ AWS_STATIC_IMPL int aws_sub_u32_checked(uint32_t a, uint32_t b, uint32_t *r) { */ AWS_STATIC_IMPL size_t aws_mul_size_saturating(size_t a, size_t b) { #if SIZE_BITS == 32 - return (size_t)aws_mul_u32_saturating(a, b); + return aws_mul_u32_saturating(a, b); #elif SIZE_BITS == 64 return aws_mul_u64_saturating(a, b); #else @@ -111,9 +111,9 @@ AWS_STATIC_IMPL int aws_mul_size_checked(size_t a, size_t b, size_t *r) { */ AWS_STATIC_IMPL size_t aws_add_size_saturating(size_t a, size_t b) { #if SIZE_BITS == 32 - return (size_t)aws_add_u32_saturating(a, b); + return aws_add_u32_saturating(a, b); #elif SIZE_BITS == 64 - return (size_t)aws_add_u64_saturating(a, b); + return aws_add_u64_saturating(a, b); #else # error "Target not supported" #endif @@ -135,9 +135,9 @@ AWS_STATIC_IMPL int aws_add_size_checked(size_t a, size_t b, size_t *r) { AWS_STATIC_IMPL size_t aws_sub_size_saturating(size_t a, size_t b) { #if SIZE_BITS == 32 - return (size_t)aws_sub_u32_saturating(a, b); + return aws_sub_u32_saturating(a, b); #elif SIZE_BITS == 64 - return (size_t)aws_sub_u64_saturating(a, b); + return aws_sub_u64_saturating(a, b); #else # error "Target not supported" #endif From 0c70993d380bdf58eacc74de9971d14a6e2dd479 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Tue, 30 Jul 2024 10:15:01 -0700 Subject: [PATCH 6/8] enable useless cast --- cmake/AwsCheckHeaders.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/AwsCheckHeaders.cmake b/cmake/AwsCheckHeaders.cmake index 2e62e0ad5..fe8980f97 100644 --- a/cmake/AwsCheckHeaders.cmake +++ b/cmake/AwsCheckHeaders.cmake @@ -68,7 +68,7 @@ function(aws_check_headers_internal target std is_cxx) # MSVC complains about windows' own header files. Use /W4 instead of /Wall target_compile_options(${HEADER_CHECKER_LIB} PRIVATE /W4 /WX) else() - target_compile_options(${HEADER_CHECKER_LIB} PRIVATE -Wall -Wextra -Wpedantic -Werror) + target_compile_options(${HEADER_CHECKER_LIB} PRIVATE -Wall -Wextra -Wpedantic -Werror -Wuseless-cast) endif() foreach(header IN LISTS ARGN) From c5c8e252b98811d4809d72978792b9be38b92d22 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Tue, 30 Jul 2024 10:30:43 -0700 Subject: [PATCH 7/8] remove useless cast --- cmake/AwsCheckHeaders.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/AwsCheckHeaders.cmake b/cmake/AwsCheckHeaders.cmake index fe8980f97..2e62e0ad5 100644 --- a/cmake/AwsCheckHeaders.cmake +++ b/cmake/AwsCheckHeaders.cmake @@ -68,7 +68,7 @@ function(aws_check_headers_internal target std is_cxx) # MSVC complains about windows' own header files. Use /W4 instead of /Wall target_compile_options(${HEADER_CHECKER_LIB} PRIVATE /W4 /WX) else() - target_compile_options(${HEADER_CHECKER_LIB} PRIVATE -Wall -Wextra -Wpedantic -Werror -Wuseless-cast) + target_compile_options(${HEADER_CHECKER_LIB} PRIVATE -Wall -Wextra -Wpedantic -Werror) endif() foreach(header IN LISTS ARGN) From 3f9f0268edf77d18a7daa779fcb289f89fc736b4 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 31 Jul 2024 14:21:56 -0700 Subject: [PATCH 8/8] more warnings? --- include/aws/common/math.inl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/aws/common/math.inl b/include/aws/common/math.inl index 07167528a..e2c56963a 100644 --- a/include/aws/common/math.inl +++ b/include/aws/common/math.inl @@ -125,9 +125,9 @@ AWS_STATIC_IMPL size_t aws_add_size_saturating(size_t a, size_t b) { */ AWS_STATIC_IMPL int aws_add_size_checked(size_t a, size_t b, size_t *r) { #if SIZE_BITS == 32 - return aws_add_u32_checked(a, b, (uint32_t *)r); + return aws_add_u32_checked(a, b, r); #elif SIZE_BITS == 64 - return aws_add_u64_checked(a, b, (uint64_t *)r); + return aws_add_u64_checked(a, b, r); #else # error "Target not supported" #endif @@ -145,9 +145,9 @@ AWS_STATIC_IMPL size_t aws_sub_size_saturating(size_t a, size_t b) { AWS_STATIC_IMPL int aws_sub_size_checked(size_t a, size_t b, size_t *r) { #if SIZE_BITS == 32 - return aws_sub_u32_checked(a, b, (uint32_t *)r); + return aws_sub_u32_checked(a, b, r); #elif SIZE_BITS == 64 - return aws_sub_u64_checked(a, b, (uint64_t *)r); + return aws_sub_u64_checked(a, b, r); #else # error "Target not supported" #endif