Skip to content

Commit a25c024

Browse files
committed
wolfssl/wolfcrypt/types.h: refactor static_assert*() as wc_static_assert*() to avoid conflicts with target-native static_assert(), and add additional coverage for C23 and MSVC C11.
wolfcrypt/test/test.c: in render_error_message(), in tests for strerror_r(), test for __USE_GNU.
1 parent 898815f commit a25c024

4 files changed

Lines changed: 34 additions & 33 deletions

File tree

src/dtls13.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ typedef struct Dtls13HandshakeHeader {
7171
byte fragmentLength[3];
7272
} Dtls13HandshakeHeader;
7373

74-
static_assert(sizeof(Dtls13HandshakeHeader) == DTLS13_HANDSHAKE_HEADER_SZ);
74+
wc_static_assert(sizeof(Dtls13HandshakeHeader) == DTLS13_HANDSHAKE_HEADER_SZ);
7575

7676
/**
7777
* struct Dtls13Recordplaintextheader: represent header of unprotected DTLSv1.3

wolfcrypt/test/test.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -841,11 +841,11 @@ static void render_error_message(const char* msg, wc_test_ret_t es)
841841
* stores an error string in the supplied buffer. this is all most
842842
* infelicitous...
843843
*/
844-
#if !defined(STRING_USER) && !defined(NO_ERROR_STRINGS) && \
844+
#if !defined(STRING_USER) && !defined(NO_ERROR_STRINGS) && \
845845
(defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199901L)) && \
846-
((defined(__GLIBC__) && (__GLIBC__ >= 2)) || \
847-
(defined(__USE_XOPEN2K) && \
848-
defined(_POSIX_C_SOURCE) && \
846+
((defined(__GLIBC__) && (__GLIBC__ >= 2) && defined(__USE_GNU)) || \
847+
(defined(__USE_XOPEN2K) && \
848+
defined(_POSIX_C_SOURCE) && \
849849
(_POSIX_C_SOURCE >= 200112L)))
850850

851851
char errno_buf[64], *errno_string;

wolfssl/wolfcrypt/settings.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,17 @@
2020
*/
2121

2222
/*
23-
* ************************************************************************
23+
* Note, this file should not be edited to activate/deactivate features.
2424
*
25-
* ******************************** NOTICE ********************************
26-
*
27-
* ************************************************************************
28-
*
29-
* This method of uncommenting a line in settings.h is outdated.
30-
*
31-
* Please use user_settings.h / WOLFSSL_USER_SETTINGS
25+
* Instead, add/edit user_settings.h, and compile with -DWOLFSSL_USER_SETTINGS
3226
*
3327
* or
3428
*
35-
* ./configure CFLAGS="-DFLAG"
29+
* ./configure CFLAGS="-DFEATURE_FLAG_TO_DEFINE -UFEATURE_FLAG_TO_CLEAR [...]"
3630
*
3731
* For more information see:
3832
*
3933
* https://www.wolfssl.com/how-do-i-manage-the-build-configuration-of-wolfssl/
40-
*
4134
*/
4235

4336

wolfssl/wolfcrypt/types.h

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,35 +1693,43 @@ typedef struct w64wrapper {
16931693
#define PRAGMA_DIAG_POP /* null expansion */
16941694
#endif
16951695

1696-
#define WC_CPP_CAT_(a, b) a ## b
1697-
#define WC_CPP_CAT(a, b) WC_CPP_CAT_(a, b)
1698-
#if (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
1699-
(defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))
1700-
#ifndef static_assert2
1701-
#define static_assert2 static_assert
1702-
#endif
1703-
#elif !defined(static_assert)
1704-
#if !defined(__cplusplus) && \
1696+
#ifndef wc_static_assert
1697+
#if (defined(__cplusplus) && (__cplusplus >= 201703L)) || \
1698+
(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)) || \
1699+
(defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))
1700+
/* directly usable variadic declaration */
1701+
#define wc_static_assert static_assert
1702+
#ifndef wc_static_assert2
1703+
#define wc_static_assert2 static_assert
1704+
#endif
1705+
#elif defined(_MSC_VER) && (__STDC_VERSION__ >= 201112L)
1706+
/* native 2-argument static_assert() */
1707+
#define wc_static_assert(expr) static_assert(expr, #expr)
1708+
#ifndef wc_static_assert2
1709+
#define wc_static_assert2(expr, msg) static_assert(expr, msg)
1710+
#endif
1711+
#elif !defined(__cplusplus) && \
17051712
!defined(__STRICT_ANSI__) && \
17061713
!defined(WOLF_C89) && \
17071714
defined(__STDC_VERSION__) && \
17081715
(__STDC_VERSION__ >= 201112L) && \
17091716
((defined(__GNUC__) && \
17101717
(__GNUC__ >= 5)) || \
17111718
defined(__clang__))
1712-
#define static_assert(expr) _Static_assert(expr, #expr)
1713-
#ifndef static_assert2
1714-
#define static_assert2(expr, msg) _Static_assert(expr, msg)
1719+
/* native 2-argument _Static_assert() */
1720+
#define wc_static_assert(expr) _Static_assert(expr, #expr)
1721+
#ifndef wc_static_assert2
1722+
#define wc_static_assert2(expr, msg) _Static_assert(expr, msg)
17151723
#endif
17161724
#else
1717-
#define static_assert(expr) \
1718-
struct WC_CPP_CAT(wc_dummy_struct_L, __LINE__)
1719-
#ifndef static_assert2
1720-
#define static_assert2(expr, msg) static_assert(expr)
1725+
/* fallback -- map wc_static_assert*() to do-nothing. */
1726+
#define wc_static_assert(expr) struct wc_static_assert_dummy_struct
1727+
#ifndef wc_static_assert2
1728+
#define wc_static_assert2(expr, msg) wc_static_assert(expr)
17211729
#endif
17221730
#endif
1723-
#elif !defined(static_assert2)
1724-
#define static_assert2(expr, msg) static_assert(expr)
1731+
#elif !defined(wc_static_assert2)
1732+
#define wc_static_assert2(expr, msg) wc_static_assert(expr)
17251733
#endif
17261734

17271735
#ifndef SAVE_VECTOR_REGISTERS

0 commit comments

Comments
 (0)