Skip to content

Commit

Permalink
Improvements for C89 compliance. Thank you @jmalak.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske committed Jan 31, 2025
1 parent 9bb1bc1 commit 0a89f9f
Show file tree
Hide file tree
Showing 14 changed files with 356 additions and 114 deletions.
56 changes: 27 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ endif()

if(CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wx -wcd=202")
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_NOT_WINDOWS_API -DWOLFSSL_HAVE_MIN -DWOLFSSL_HAVE_MAX -DNO_WRITEV -DWOLFSSL_NO_SOCK -DWOLFSSL_USER_IO")
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_HAVE_MIN -DWOLFSSL_HAVE_MAX -DNO_WRITEV")
elseif(WIN32)
# Windows cl.exe does not support the -Wextra, -Wno-unused and -Werror flags.
set(CMAKE_C_FLAGS "-Wall ${CMAKE_C_FLAGS}")
Expand Down Expand Up @@ -2492,34 +2492,32 @@ if(WOLFSSL_EXAMPLES)
${WOLFSSL_OUTPUT_BASE}/examples/benchmark)
endif()

if(NOT WOLFSSL_SINGLE_THREADED)
# Build unit tests
add_executable(unit_test
tests/api.c
tests/api/ascon.c
tests/hash.c
tests/srp.c
tests/suites.c
tests/w64wrapper.c
tests/unit.c
tests/quic.c
examples/server/server.c
examples/client/client.c)
target_include_directories(unit_test PRIVATE
${CMAKE_CURRENT_BINARY_DIR})
target_compile_options(unit_test PUBLIC "-DNO_MAIN_DRIVER")
target_link_libraries(unit_test wolfssl)
target_link_libraries(unit_test Threads::Threads)
set_property(TARGET unit_test
PROPERTY RUNTIME_OUTPUT_DIRECTORY
${WOLFSSL_OUTPUT_BASE}/tests/)
set_property(TARGET unit_test
PROPERTY RUNTIME_OUTPUT_NAME
unit.test)
add_test(NAME unit_test
COMMAND $<TARGET_FILE:unit_test>
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
# Build unit tests
add_executable(unit_test
tests/api.c
tests/api/ascon.c
tests/hash.c
tests/srp.c
tests/suites.c
tests/w64wrapper.c
tests/unit.c
tests/quic.c
examples/server/server.c
examples/client/client.c)
target_include_directories(unit_test PRIVATE
${CMAKE_CURRENT_BINARY_DIR})
target_compile_options(unit_test PUBLIC "-DNO_MAIN_DRIVER")
target_link_libraries(unit_test wolfssl)
target_link_libraries(unit_test Threads::Threads)
set_property(TARGET unit_test
PROPERTY RUNTIME_OUTPUT_DIRECTORY
${WOLFSSL_OUTPUT_BASE}/tests/)
set_property(TARGET unit_test
PROPERTY RUNTIME_OUTPUT_NAME
unit.test)
add_test(NAME unit_test
COMMAND $<TARGET_FILE:unit_test>
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()

if(WOLFSSL_CRYPT_TESTS)
Expand Down
1 change: 1 addition & 0 deletions src/ssl_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#ifdef WOLFSSL_SYS_CA_CERTS

#ifdef _WIN32
#define _WINSOCKAPI_
#include <windows.h>
#include <wincrypt.h>

Expand Down
11 changes: 4 additions & 7 deletions src/wolfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@
#include <errno.h>
#endif

#ifdef _WIN32_WCE
/* On WinCE winsock2.h must be included before windows.h for socket stuff */
#include <winsock2.h>
#endif

#include <wolfssl/internal.h>
#include <wolfssl/error-ssl.h>
#include <wolfssl/wolfio.h>
Expand All @@ -56,7 +51,9 @@ int Nucleus_Net_Errno;
#endif

#if defined(USE_WOLFSSL_IO) || defined(HAVE_HTTP_CLIENT)
#ifndef USE_WINDOWS_API
#ifdef USE_WINDOWS_API
#include <winsock2.h>
#else
#if defined(WOLFSSL_LWIP) && !defined(WOLFSSL_APACHE_MYNEWT)
#elif defined(ARDUINO)
#elif defined(FREESCALE_MQX)
Expand Down Expand Up @@ -248,7 +245,7 @@ static int TranslateIoReturnCode(int err, SOCKET_T sd, int direction)
return WOLFSSL_CBIO_ERR_CONN_CLOSE;
}

#if defined(_WIN32)
#if defined(_WIN32) && !defined(__WATCOMC__)
strcpy_s(errstr, sizeof(errstr), "\tGeneral error: ");
errstr_offset = strlen(errstr);
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
Expand Down
43 changes: 26 additions & 17 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -79291,19 +79291,22 @@ static int test_wc_ParseCert_Error(void)
const byte c4[] = { 0x02, 0x80, 0x10, 0x00, 0x00};

/* Test data */
const struct testStruct {
struct testStruct {
const byte* c;
word32 cSz;
const int expRet;
} t[] = {
{c0, sizeof(c0), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid bit-string length */
{c1, sizeof(c1), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid bit-string length */
{c2, sizeof(c2), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid integer length (zero) */
{c3, sizeof(c3), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Valid INTEGER, but buffer too short */
{c4, sizeof(c4), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Valid INTEGER, but not in bit-string */
};
int expRet;
} t[5];
const int tSz = (int)(sizeof(t) / sizeof(struct testStruct));

#define INIT_TEST_DATA(i,x,y) \
t[i].c = x; t[i].cSz = sizeof(x); t[i].expRet = y
INIT_TEST_DATA(0, c0, WC_NO_ERR_TRACE(ASN_PARSE_E) );
INIT_TEST_DATA(1, c1, WC_NO_ERR_TRACE(ASN_PARSE_E) );
INIT_TEST_DATA(2, c2, WC_NO_ERR_TRACE(ASN_PARSE_E) );
INIT_TEST_DATA(3, c3, WC_NO_ERR_TRACE(ASN_PARSE_E) );
INIT_TEST_DATA(4, c4, WC_NO_ERR_TRACE(ASN_PARSE_E) );
#undef INIT_TEST_DATA

for (i = 0; i < tSz; i++) {
WOLFSSL_MSG_EX("i == %d", i);
wc_InitDecodedCert(&decodedCert, t[i].c, t[i].cSz, NULL);
Expand Down Expand Up @@ -81873,7 +81876,10 @@ static char earlyDataBuffer[1];
static int test_tls13_apis(void)
{
EXPECT_DECLS;
int ret;
#if defined(HAVE_SUPPORTED_CURVES) && defined(HAVE_ECC) && \
(!defined(NO_WOLFSSL_SERVER) || !defined(NO_WOLFSSL_CLIENT))
int ret;
#endif
#ifndef WOLFSSL_NO_TLS12
#ifndef NO_WOLFSSL_CLIENT
WOLFSSL_CTX* clientTls12Ctx = NULL;
Expand Down Expand Up @@ -81997,8 +82003,6 @@ static int test_tls13_apis(void)
int kyberLevel;
#endif

(void)ret;

#ifndef WOLFSSL_NO_TLS12
#ifndef NO_WOLFSSL_CLIENT
clientTls12Ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
Expand Down Expand Up @@ -93029,10 +93033,10 @@ static int test_wolfSSL_CTX_set_timeout(void)
EXPECT_DECLS;
#if !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) && \
!defined(NO_SESSION_CACHE)
int timeout;
WOLFSSL_CTX* ctx = NULL;

(void)timeout;
#if defined(WOLFSSL_ERROR_CODE_OPENSSL)
int timeout;
#endif

ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));

Expand Down Expand Up @@ -102878,14 +102882,19 @@ static const char* apitest_res_string(int res)

#ifndef WOLFSSL_UNIT_TEST_NO_TIMING
static double gettime_secs(void)
#if defined(_MSC_VER) && defined(_WIN32)
#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__))
{
/* there's no gettimeofday for Windows, so we'll use system time */
#define EPOCH_DIFF 11644473600LL
FILETIME currentFileTime;
ULARGE_INTEGER uli = { 0, 0 };

#if defined(__WATCOMC__)
GetSystemTimeAsFileTime(&currentFileTime);
#else
GetSystemTimePreciseAsFileTime(&currentFileTime);
#endif

ULARGE_INTEGER uli = { 0, 0 };
uli.LowPart = currentFileTime.dwLowDateTime;
uli.HighPart = currentFileTime.dwHighDateTime;

Expand Down
1 change: 1 addition & 0 deletions wolfcrypt/src/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ This library contains implementation for the random number generator.
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
#define _WINSOCKAPI_
#include <windows.h>
#include <wincrypt.h>
#elif defined(HAVE_WNR)
Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/src/sp_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -5136,7 +5136,7 @@ int sp_init_size(sp_int* a, unsigned int size)
int err = MP_OKAY;

/* Validate parameters. Don't use size more than max compiled. */
if ((a == NULL) || ((size <= 0) || (size > SP_INT_DIGITS))) {
if ((a == NULL) || ((size == 0) || (size > SP_INT_DIGITS))) {
err = MP_VAL;
}

Expand Down
Loading

0 comments on commit 0a89f9f

Please sign in to comment.