From aba04c562bdda946392c04b10e253c3e35cfb946 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 26 May 2025 16:26:03 +0200 Subject: [PATCH] Compiling - fix warnings with MSVC 17.14 New warnings come from 3 places 1. Warning C5287: Warning comes from json_lib.c from code like compile_time_assert((int) JSON_VALUE_NULL == (int) JSV_NULL); 2. Warning C5287: Similar warning come from wc_static_assert() from code in wolfSSL's header file 3. Warning C5286 in WolfSSL code, -enum_value (i.e multiplying enum with -1)is used To fix: - Disable warnings in WolfSSL code, using /wd flag. - workaround warning for users of WolfSSL, disable wc_static_assert() with -DWC_NO_STATIC_ASSERT compile flag - Rewrite some compile_time_assert in json_lib.c to avoid warning. - add target_link_libraries(vio ${SSL_LIBRARIES}) so that vio picks up -DWC_NO_STATIC_ASSERT --- extra/wolfssl/CMakeLists.txt | 3 ++- strings/json_lib.c | 14 +++++++------- vio/CMakeLists.txt | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/extra/wolfssl/CMakeLists.txt b/extra/wolfssl/CMakeLists.txt index dc2f8092762..38203a07911 100644 --- a/extra/wolfssl/CMakeLists.txt +++ b/extra/wolfssl/CMakeLists.txt @@ -126,7 +126,8 @@ endif() # Silence some warnings if(MSVC) # truncation warnings - target_compile_options(wolfssl PRIVATE $<$:/wd4244>) + target_compile_options(wolfssl PRIVATE $<$:/wd4244 /wd5287 /wd5286>) + target_compile_definitions(wolfssl PUBLIC WC_NO_STATIC_ASSERT) if(CMAKE_C_COMPILER_ID MATCHES Clang) target_compile_options(wolfssl PRIVATE $<$:-Wno-incompatible-function-pointer-types>) endif() diff --git a/strings/json_lib.c b/strings/json_lib.c index a04cee573c6..5f55a83c9d4 100644 --- a/strings/json_lib.c +++ b/strings/json_lib.c @@ -1788,13 +1788,13 @@ static enum json_types smart_read_value(json_engine_t *je, *value_len= (int) ((char *) je->s.c_str - *value); } - compile_time_assert((int) JSON_VALUE_OBJECT == (int) JSV_OBJECT); - compile_time_assert((int) JSON_VALUE_ARRAY == (int) JSV_ARRAY); - compile_time_assert((int) JSON_VALUE_STRING == (int) JSV_STRING); - compile_time_assert((int) JSON_VALUE_NUMBER == (int) JSV_NUMBER); - compile_time_assert((int) JSON_VALUE_TRUE == (int) JSV_TRUE); - compile_time_assert((int) JSON_VALUE_FALSE == (int) JSV_FALSE); - compile_time_assert((int) JSON_VALUE_NULL == (int) JSV_NULL); + compile_time_assert((enum json_types)JSON_VALUE_OBJECT == JSV_OBJECT); + compile_time_assert((enum json_types)JSON_VALUE_ARRAY == JSV_ARRAY); + compile_time_assert((enum json_types)JSON_VALUE_STRING == JSV_STRING); + compile_time_assert((enum json_types)JSON_VALUE_NUMBER == JSV_NUMBER); + compile_time_assert((enum json_types)JSON_VALUE_TRUE == JSV_TRUE); + compile_time_assert((enum json_types)JSON_VALUE_FALSE == JSV_FALSE); + compile_time_assert((enum json_types)JSON_VALUE_NULL == JSV_NULL); return (enum json_types) je->value_type; diff --git a/vio/CMakeLists.txt b/vio/CMakeLists.txt index 85810840273..e7987cb9c2f 100644 --- a/vio/CMakeLists.txt +++ b/vio/CMakeLists.txt @@ -20,3 +20,4 @@ ADD_DEFINITIONS(${SSL_DEFINES}) SET(VIO_SOURCES vio.c viosocket.c viossl.c viopipe.c viosslfactories.c) ADD_CONVENIENCE_LIBRARY(vio ${VIO_SOURCES}) TARGET_LINK_LIBRARIES(vio ${LIBSOCKET}) +TARGET_LINK_LIBRARIES(vio ${SSL_LIBRARIES})