diff --git a/client/X11/xf_keyboard.c b/client/X11/xf_keyboard.c index efd091c2f..6641257e2 100644 --- a/client/X11/xf_keyboard.c +++ b/client/X11/xf_keyboard.c @@ -23,7 +23,9 @@ #include #include #include +#include +#include #include #include #include @@ -191,6 +193,7 @@ void xf_keyboard_release_all_keypress(xfContext* xfc) { WINPR_ASSERT(xfc); + WINPR_STATIC_ASSERT(ARRAYSIZE(xfc->KeyboardState) <= UINT32_MAX); for (size_t keycode = 0; keycode < ARRAYSIZE(xfc->KeyboardState); keycode++) { if (xfc->KeyboardState[keycode]) diff --git a/libfreerdp/locale/keyboard.c b/libfreerdp/locale/keyboard.c index d8f00e0b1..9de4489eb 100644 --- a/libfreerdp/locale/keyboard.c +++ b/libfreerdp/locale/keyboard.c @@ -21,7 +21,9 @@ #include #include +#include +#include #include #include @@ -324,6 +326,7 @@ DWORD freerdp_keyboard_init(DWORD keyboardLayoutId) ZeroMemory(VIRTUAL_SCANCODE_TO_X11_KEYCODE, sizeof(VIRTUAL_SCANCODE_TO_X11_KEYCODE)); + WINPR_STATIC_ASSERT(ARRAYSIZE(VIRTUAL_SCANCODE_TO_X11_KEYCODE) <= UINT32_MAX); for (size_t keycode = 0; keycode < ARRAYSIZE(VIRTUAL_SCANCODE_TO_X11_KEYCODE); keycode++) { const DWORD x11 = X11_KEYCODE_TO_VIRTUAL_SCANCODE[keycode]; diff --git a/server/shadow/shadow_server.c b/server/shadow/shadow_server.c index a47d4a568..1045d3a99 100644 --- a/server/shadow/shadow_server.c +++ b/server/shadow/shadow_server.c @@ -21,7 +21,9 @@ #include #include +#include +#include #include #include #include @@ -797,6 +799,8 @@ static BOOL shadow_server_create_certificate(rdpShadowServer* server, const char { BOOL rc = FALSE; char* makecert_argv[6] = { "makecert", "-rdp", "-live", "-silent", "-y", "5" }; + + WINPR_STATIC_ASSERT(ARRAYSIZE(makecert_argv) <= INT_MAX); const size_t makecert_argc = ARRAYSIZE(makecert_argv); MAKECERT_CONTEXT* makecert = makecert_context_new(); @@ -804,7 +808,6 @@ static BOOL shadow_server_create_certificate(rdpShadowServer* server, const char if (!makecert) goto out_fail; - WINPR_ASSERT(makecert_argc <= INT_MAX); if (makecert_context_process(makecert, (int)makecert_argc, makecert_argv) < 0) goto out_fail; diff --git a/winpr/include/config/wtypes.h.in b/winpr/include/config/wtypes.h.in index 6d42d890a..67aee9404 100644 --- a/winpr/include/config/wtypes.h.in +++ b/winpr/include/config/wtypes.h.in @@ -22,32 +22,6 @@ #include -// C99 related macros -#if defined(__STDC__) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -#define WINPR_RESTRICT restrict -#elif defined(_MSC_VER) && _MSC_VER >= 1900 -#define WINPR_RESTRICT __restrict -#else -#define WINPR_RESTRICT -#endif - -// C23 related macros -#if defined(__STDC__) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L) -#define WINPR_FALLTHROUGH \ - (void)0; \ - [[fallthrough]]; -#elif defined(__clang__) -#define WINPR_FALLTHROUGH \ - (void)0; \ - __attribute__((fallthrough)); -#elif defined(__GNUC__) && (__GNUC__ >= 7) -#define WINPR_FALLTHROUGH \ - (void)0; \ - __attribute__((fallthrough)); -#else -#define WINPR_FALLTHROUGH (void)0; -#endif - /* Set by CMake during configuration */ #cmakedefine WINPR_HAVE_STDINT_H #cmakedefine WINPR_HAVE_STDBOOL_H diff --git a/winpr/include/winpr/assert.h b/winpr/include/winpr/assert.h index af8daac73..9d4d2a4b0 100644 --- a/winpr/include/winpr/assert.h +++ b/winpr/include/winpr/assert.h @@ -22,6 +22,8 @@ #define WINPR_ASSERT_H #include +#include + #include #include #include @@ -56,8 +58,28 @@ extern "C" #endif #else -#include #define WINPR_ASSERT(cond) assert(cond) #endif +#ifdef __cplusplus +extern "C" +{ +#endif +#if defined(__cplusplus) && (__cplusplus >= 201703L) // C++ 17 +#define WINPR_STATIC_ASSERT(cond) static_assert(cond) +#elif defined(__cplusplus) && (__cplusplus >= 201103L) // C++ 11 +#define WINPR_STATIC_ASSERT(cond) static_assert(cond, #cond) +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L) // C23 +#define WINPR_STATIC_ASSERT(cond) static_assert(cond) +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) // C11 +#define WINPR_STATIC_ASSERT(cond) _Static_assert(cond, #cond) +#else +WINPR_PRAGMA_WARNING("static-assert macro not supported on this platform") +#define WINPR_STATIC_ASSERT(cond) assert(cond) +#endif + +#ifdef __cplusplus +} +#endif + #endif /* WINPR_ERROR_H */ diff --git a/winpr/include/winpr/platform.h b/winpr/include/winpr/platform.h index 07b10046d..8483996e9 100644 --- a/winpr/include/winpr/platform.h +++ b/winpr/include/winpr/platform.h @@ -27,8 +27,36 @@ #define WINPR_PRAGMA_WARNING(msg) WINPR_DO_PRAGMA(GCC warning #msg) #elif defined(__clang__) #define WINPR_PRAGMA_WARNING(msg) WINPR_DO_PRAGMA(GCC warning #msg) -#elif defined(_MSC_VER) +#elif defined(_MSC_VER) && (_MSC_VER >= 1920) #define WINPR_PRAGMA_WARNING(msg) WINPR_DO_PRAGMA(message \x28 #msg \x29) +#else +#define WINPR_PRAGMA_WARNING(msg) +#endif + +// C99 related macros +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +#define WINPR_RESTRICT restrict +#elif defined(_MSC_VER) && _MSC_VER >= 1900 +#define WINPR_RESTRICT __restrict +#else +#define WINPR_RESTRICT +#endif + +// C23 related macros +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L) +#define WINPR_FALLTHROUGH \ + (void)0; \ + [[fallthrough]]; +#elif defined(__clang__) +#define WINPR_FALLTHROUGH \ + (void)0; \ + __attribute__((fallthrough)); +#elif defined(__GNUC__) && (__GNUC__ >= 7) +#define WINPR_FALLTHROUGH \ + (void)0; \ + __attribute__((fallthrough)); +#else +#define WINPR_FALLTHROUGH (void)0; #endif #if defined(__clang__) diff --git a/winpr/include/winpr/winpr.h b/winpr/include/winpr/winpr.h index 715231f9a..16af05c51 100644 --- a/winpr/include/winpr/winpr.h +++ b/winpr/include/winpr/winpr.h @@ -65,7 +65,7 @@ #define WINPR_FORMAT_ARG _Printf_format_string_ #endif -#if defined(__STDC__) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L) +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L) #define WINPR_DEPRECATED(obj) [[deprecated]] obj #define WINPR_DEPRECATED_VAR(text, obj) [[deprecated(text)]] obj #define WINPR_NORETURN(obj) [[noreturn]] obj