From ac2fd6524afdbaa42266b2c8c198eac7a7ca0a18 Mon Sep 17 00:00:00 2001 From: makise-homura Date: Tue, 18 Aug 2020 21:59:46 +0300 Subject: [PATCH 1/6] Support building on e2k (Elbrus) architecture Signed-off-by: makise-homura --- CMakeLists.txt | 15 ++++++++++++++- ChangeLog.d/e2k-support.txt | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 ChangeLog.d/e2k-support.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index f8df14007..3fb4d364d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,6 +152,8 @@ endfunction(link_to_source) string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}") +include(CheckCCompilerFlag) + if(CMAKE_COMPILER_IS_GNU) # some warnings we want are not available with old GCC versions # note: starting with CMake 2.8 we could use CMAKE_C_COMPILER_VERSION @@ -168,7 +170,18 @@ if(CMAKE_COMPILER_IS_GNU) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow") endif() if (GCC_VERSION VERSION_GREATER 5.0) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-signedness") + CHECK_C_COMPILER_FLAG("-Wformat-signedness" C_COMPILER_SUPPORTS_WFORMAT_SIGNEDNESS) + if(C_COMPILER_SUPPORTS_WFORMAT_SIGNEDNESS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-signedness") + endif() + endif() + CHECK_C_COMPILER_FLAG("-Wno-signed-one-bit-field" C_COMPILER_SUPPORTS_WSIGNED_ONE_BIT_FIELD) + if(C_COMPILER_SUPPORTS_WSIGNED_ONE_BIT_FIELD) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-signed-one-bit-field") + endif() + CHECK_C_COMPILER_FLAG("-Wno-sign-compare" C_COMPILER_SUPPORTS_WSIGN_COMPARE) + if(C_COMPILER_SUPPORTS_WSIGN_COMPARE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-sign-compare") endif() set(CMAKE_C_FLAGS_RELEASE "-O2") set(CMAKE_C_FLAGS_DEBUG "-O0 -g3") diff --git a/ChangeLog.d/e2k-support.txt b/ChangeLog.d/e2k-support.txt new file mode 100644 index 000000000..19cc3ad68 --- /dev/null +++ b/ChangeLog.d/e2k-support.txt @@ -0,0 +1,5 @@ +Features + * Support building on e2k (Elbrus) architecture: correctly enable + -Wformat-signedness, and pass -Wno-signed-one-bit-field and + -Wno-sign-compare to get rid of excess warnings. Contributed by + makise-homura (Igor Molchanov) . From 0be6aa9957e6b27f6256660f3bd032969f2c56f4 Mon Sep 17 00:00:00 2001 From: makise-homura Date: Tue, 18 Aug 2020 23:52:53 +0300 Subject: [PATCH 2/6] Get back -Wsign-compare and fix sources according to it Signed-off-by: makise-homura --- CMakeLists.txt | 4 ---- library/ssl_msg.c | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fb4d364d..d2cf44629 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -179,10 +179,6 @@ if(CMAKE_COMPILER_IS_GNU) if(C_COMPILER_SUPPORTS_WSIGNED_ONE_BIT_FIELD) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-signed-one-bit-field") endif() - CHECK_C_COMPILER_FLAG("-Wno-sign-compare" C_COMPILER_SUPPORTS_WSIGN_COMPARE) - if(C_COMPILER_SUPPORTS_WSIGN_COMPARE) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-sign-compare") - endif() set(CMAKE_C_FLAGS_RELEASE "-O2") set(CMAKE_C_FLAGS_DEBUG "-O0 -g3") set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage") diff --git a/library/ssl_msg.c b/library/ssl_msg.c index d32afac56..259a71d2f 100644 --- a/library/ssl_msg.c +++ b/library/ssl_msg.c @@ -2048,7 +2048,7 @@ int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want ) if( ret < 0 ) return( ret ); - if ( (size_t)ret > len || ( INT_MAX > SIZE_MAX && ret > SIZE_MAX ) ) + if ( (size_t)ret > len || ( INT_MAX > SIZE_MAX && (size_t)ret > SIZE_MAX ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "f_recv returned %d bytes but only %lu were requested", @@ -2102,7 +2102,7 @@ int mbedtls_ssl_flush_output( mbedtls_ssl_context *ssl ) if( ret <= 0 ) return( ret ); - if( (size_t)ret > ssl->out_left || ( INT_MAX > SIZE_MAX && ret > SIZE_MAX ) ) + if( (size_t)ret > ssl->out_left || ( INT_MAX > SIZE_MAX && (size_t)ret > SIZE_MAX ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "f_send returned %d bytes but only %lu bytes were sent", From e74f372330549bf4cbd8f4d880aceb87d7516005 Mon Sep 17 00:00:00 2001 From: makise-homura Date: Tue, 18 Aug 2020 23:57:48 +0300 Subject: [PATCH 3/6] Get back -Wsigned-one-bit-field and fix sources according to it Signed-off-by: makise-homura --- CMakeLists.txt | 4 ---- tests/include/test/macros.h | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d2cf44629..88332464b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,10 +175,6 @@ if(CMAKE_COMPILER_IS_GNU) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-signedness") endif() endif() - CHECK_C_COMPILER_FLAG("-Wno-signed-one-bit-field" C_COMPILER_SUPPORTS_WSIGNED_ONE_BIT_FIELD) - if(C_COMPILER_SUPPORTS_WSIGNED_ONE_BIT_FIELD) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-signed-one-bit-field") - endif() set(CMAKE_C_FLAGS_RELEASE "-O2") set(CMAKE_C_FLAGS_DEBUG "-O0 -g3") set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage") diff --git a/tests/include/test/macros.h b/tests/include/test/macros.h index aaf13add0..21552e760 100644 --- a/tests/include/test/macros.h +++ b/tests/include/test/macros.h @@ -75,7 +75,7 @@ /* A compile-time constant with the value 0. If `const_expr` is not a * compile-time constant with a nonzero value, cause a compile-time error. */ #define STATIC_ASSERT_EXPR( const_expr ) \ - ( 0 && sizeof( struct { int STATIC_ASSERT : 1 - 2 * ! ( const_expr ); } ) ) + ( 0 && sizeof( struct { unsigned int STATIC_ASSERT : 1 - 2 * ! ( const_expr ); } ) ) /* Return the scalar value `value` (possibly promoted). This is a compile-time * constant if `value` is. `condition` must be a compile-time constant. * If `condition` is false, arrange to cause a compile-time error. */ From e5595501cea24260ed491700caee80d7c710a433 Mon Sep 17 00:00:00 2001 From: makise-homura Date: Wed, 19 Aug 2020 01:33:15 +0300 Subject: [PATCH 4/6] Fix e2k support changelog snippet Signed-off-by: makise-homura --- ChangeLog.d/e2k-support.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ChangeLog.d/e2k-support.txt b/ChangeLog.d/e2k-support.txt index 19cc3ad68..023b1888e 100644 --- a/ChangeLog.d/e2k-support.txt +++ b/ChangeLog.d/e2k-support.txt @@ -1,5 +1,5 @@ Features * Support building on e2k (Elbrus) architecture: correctly enable - -Wformat-signedness, and pass -Wno-signed-one-bit-field and - -Wno-sign-compare to get rid of excess warnings. Contributed by - makise-homura (Igor Molchanov) . + -Wformat-signedness, and fix the code that causes signed-one-bit-field + and sign-compare warnings. Contributed by makise-homura (Igor Molchanov) + . From e014fece509a5c486c685f384e1286fba2653ab7 Mon Sep 17 00:00:00 2001 From: makise-homura Date: Sat, 22 Aug 2020 23:56:46 +0300 Subject: [PATCH 5/6] Don't forget to free G, P, Q, ctr_drbg, and entropy I might be wrong, but lcc's optimizer is curious about this, and I am too: shouldn't we free allocated stuff correctly before exiting `dh_genprime` in this certain point of code? Signed-off-by: makise-homura --- programs/pkey/dh_genprime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/pkey/dh_genprime.c b/programs/pkey/dh_genprime.c index 5293f899c..81876b3cf 100644 --- a/programs/pkey/dh_genprime.c +++ b/programs/pkey/dh_genprime.c @@ -91,7 +91,7 @@ int main( int argc, char **argv ) { usage: mbedtls_printf( USAGE ); - mbedtls_exit( exit_code ); + goto exit; } for( i = 1; i < argc; i++ ) From af9513bb48407544c301fe2a06b69793c38e7a8a Mon Sep 17 00:00:00 2001 From: makise-homura Date: Mon, 24 Aug 2020 18:26:27 +0300 Subject: [PATCH 6/6] A different approach of signed-to-unsigned comparison Suggsted by @hanno-arm Signed-off-by: makise-homura --- library/ssl_msg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/ssl_msg.c b/library/ssl_msg.c index 259a71d2f..0d74e6d82 100644 --- a/library/ssl_msg.c +++ b/library/ssl_msg.c @@ -2048,7 +2048,7 @@ int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want ) if( ret < 0 ) return( ret ); - if ( (size_t)ret > len || ( INT_MAX > SIZE_MAX && (size_t)ret > SIZE_MAX ) ) + if ( (size_t)ret > len || ( INT_MAX > SIZE_MAX && ret > (int)SIZE_MAX ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "f_recv returned %d bytes but only %lu were requested", @@ -2102,7 +2102,7 @@ int mbedtls_ssl_flush_output( mbedtls_ssl_context *ssl ) if( ret <= 0 ) return( ret ); - if( (size_t)ret > ssl->out_left || ( INT_MAX > SIZE_MAX && (size_t)ret > SIZE_MAX ) ) + if( (size_t)ret > ssl->out_left || ( INT_MAX > SIZE_MAX && ret > (int)SIZE_MAX ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "f_send returned %d bytes but only %lu bytes were sent",