diff --git a/examples/echoserver/echoserver.c b/examples/echoserver/echoserver.c index ead3eb39..e9ea78eb 100644 --- a/examples/echoserver/echoserver.c +++ b/examples/echoserver/echoserver.c @@ -86,17 +86,34 @@ typedef int SOCKET_T; #define CYASSL_THREAD __stdcall #endif - typedef struct { SOCKET_T clientFd; } thread_ctx_t; -static INLINE void err_sys(const char* msg) +#ifdef __GNUC__ + #define WS_NORETURN __attribute__((noreturn)) +#else + #define WS_NORETURN +#endif + + +static INLINE WS_NORETURN void err_sys(const char* msg) { printf("server error: %s\n", msg); + +#ifndef __GNUC__ + /* scan-build (which pretends to be gnuc) can get confused and think the + * msg pointer can be null even when hardcoded and then it won't exit, + * making null pointer checks above the err_sys() call useless. + * We could just always exit() but some compilers will complain about no + * possible return, with gcc we know the attribute to handle that with + * WS_NORETURN. */ if (msg) +#endif + { exit(EXIT_FAILURE); + } } @@ -669,4 +686,3 @@ int main(void) return 0; } - diff --git a/examples/server/server.c b/examples/server/server.c index 4356105a..73251767 100644 --- a/examples/server/server.c +++ b/examples/server/server.c @@ -84,17 +84,34 @@ typedef int SOCKET_T; #define CYASSL_THREAD __stdcall #endif - typedef struct { SOCKET_T clientFd; } thread_ctx_t; -static INLINE void err_sys(const char* msg) +#ifdef __GNUC__ + #define WS_NORETURN __attribute__((noreturn)) +#else + #define WS_NORETURN +#endif + + +static INLINE WS_NORETURN void err_sys(const char* msg) { printf("server error: %s\n", msg); + +#ifndef __GNUC__ + /* scan-build (which pretends to be gnuc) can get confused and think the + * msg pointer can be null even when hardcoded and then it won't exit, + * making null pointer checks above the err_sys() call useless. + * We could just always exit() but some compilers will complain about no + * possible return, with gcc we know the attribute to handle that with + * WS_NORETURN. */ if (msg) +#endif + { exit(EXIT_FAILURE); + } }