From dd7f9b618de868c6a8158c50d750f9edb91dec38 Mon Sep 17 00:00:00 2001 From: toddouska Date: Thu, 25 Aug 2016 12:23:57 -0700 Subject: [PATCH 1/2] make sure static analysis realizes err_sys does exit() --- wolfssl/test.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wolfssl/test.h b/wolfssl/test.h index 360d3e908..cac07f7da 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -358,8 +358,7 @@ static const word16 wolfSSLPort = 11111; static INLINE void err_sys(const char* msg) { printf("wolfSSL error: %s\n", msg); - if (msg) - exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } From 86e889a7fa842e0cba848fa9fd2805943f41e1db Mon Sep 17 00:00:00 2001 From: toddouska Date: Fri, 26 Aug 2016 10:20:58 -0700 Subject: [PATCH 2/2] only force exit() in all cases with gcc since we know noreturn attribute there --- wolfssl/test.h | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/wolfssl/test.h b/wolfssl/test.h index cac07f7da..f23748ee4 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -355,10 +355,29 @@ void join_thread(THREAD_TYPE); #endif static const word16 wolfSSLPort = 11111; -static INLINE void err_sys(const char* msg) + +#if defined(__GNUC__) + #define WC_NORETURN __attribute__((noreturn)) +#else + #define WC_NORETURN +#endif + +static INLINE WC_NORETURN void err_sys(const char* msg) { printf("wolfSSL error: %s\n", msg); - exit(EXIT_FAILURE); + +#if !defined(__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 + * WC_NORETURN. */ + if (msg) +#endif + { + exit(EXIT_FAILURE); + } }