diff --git a/wolfssl/internal.h b/wolfssl/internal.h index 943e07d26f..e914a78132 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -3447,7 +3447,7 @@ typedef struct SignatureAlgorithms { #pragma warning(disable: 4200) #endif /* sig/algo to offer */ - byte hashSigAlgo[WC_FLEXIBLE_ARRAY_MEMBER]; + byte hashSigAlgo[WC_FLEXIBLE_ARRAY_SIZE]; } SignatureAlgorithms; WOLFSSL_LOCAL SignatureAlgorithms* TLSX_SignatureAlgorithms_New( @@ -3630,7 +3630,7 @@ typedef struct ExternalTicket { byte key_name[WOLFSSL_TICKET_NAME_SZ]; /* key context name - 16 */ byte iv[WOLFSSL_TICKET_IV_SZ]; /* this ticket's iv - 16 */ byte enc_len[OPAQUE16_LEN]; /* encrypted length - 2 */ - byte enc_ticket[WC_FLEXIBLE_ARRAY_MEMBER]; /* encrypted ticket - var length + byte enc_ticket[WC_FLEXIBLE_ARRAY_SIZE]; /* encrypted ticket - var length * + total mac - 32 */ } ExternalTicket; @@ -3715,7 +3715,7 @@ typedef struct Cookie { #ifdef _MSC_VER #pragma warning(disable: 4200) #endif - byte data[WC_FLEXIBLE_ARRAY_MEMBER]; + byte data[WC_FLEXIBLE_ARRAY_SIZE]; } Cookie; WOLFSSL_LOCAL int TLSX_Cookie_Use(const WOLFSSL* ssl, const byte* data, @@ -5771,7 +5771,7 @@ typedef struct DtlsFragBucket { #ifdef _MSC_VER #pragma warning(disable: 4200) #endif - byte buf[WC_FLEXIBLE_ARRAY_MEMBER]; + byte buf[WC_FLEXIBLE_ARRAY_SIZE]; } DtlsFragBucket; typedef struct DtlsMsg { diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index 3f3a7839fa..fc37b4a569 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -221,13 +221,27 @@ typedef const char wcchar[]; #define WOLF_ENUM_DUMMY_LAST_ELEMENT(prefix) /* null expansion */ #endif -#if defined(WOLF_C89) - /* C99 flexible array member, or the C89 "struct hack" fallback. +#if defined(WC_FLEXIBLE_ARRAY_SIZE) + /* keep override value. */ +#elif defined(__cplusplus) + /* No C++ standard has FAMs; [] and [0] are vendor extensions. + * Use the struct hack. */ + #define WC_FLEXIBLE_ARRAY_SIZE 1 +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) + /* Standard C99+ flexible array member -- valid even under + * __STRICT_ANSI__ / -pedantic. */ + #define WC_FLEXIBLE_ARRAY_SIZE +#elif defined(__STRICT_ANSI__) || defined(WOLF_C89) + /* C89 "struct hack" fallback. * See http://c-faq.com/struct/structhack.html */ - #define WC_FLEXIBLE_ARRAY_MEMBER 1 + #define WC_FLEXIBLE_ARRAY_SIZE 1 +#elif defined(__GNUC__) || defined(__clang__) || \ + (defined(_MSC_VER) && !defined(__cplusplus)) + /* gnu89 etc.: [] accepted as an extension without -pedantic; + * MSVC C mode accepts it too (C4200, off by default at /W3). */ + #define WC_FLEXIBLE_ARRAY_SIZE #else - /* empty: C99 flexible array member */ - #define WC_FLEXIBLE_ARRAY_MEMBER + #define WC_FLEXIBLE_ARRAY_SIZE 1 #endif /* try to set SIZEOF_LONG or SIZEOF_LONG_LONG if user didn't */