From fa3f0660b6f7264e266cd24fad3ca387e7da335f Mon Sep 17 00:00:00 2001 From: kaleb-himes Date: Thu, 31 Dec 2015 13:59:11 -0700 Subject: [PATCH 1/3] compiler warning about myStack use --- wolfssl/test.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wolfssl/test.h b/wolfssl/test.h index b09c632d8..ebe722432 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -1374,7 +1374,7 @@ typedef THREAD_RETURN WOLFSSL_THREAD (*thread_func)(void* args); static INLINE void StackSizeCheck(func_args* args, thread_func tf) { int ret, i, used; - unsigned char* myStack; + unsigned char* myStack = NULL; int stackSize = 1024*128; pthread_attr_t myAttr; pthread_t threadId; @@ -1388,7 +1388,10 @@ static INLINE void StackSizeCheck(func_args* args, thread_func tf) if (ret != 0) err_sys("posix_memalign failed\n"); - memset(myStack, 0x01, stackSize); + XMEMSET(myStack, 0x01, stackSize); + + if (myStack == NULL) + err_sys("Failed to initialize myStack"); ret = pthread_attr_init(&myAttr); if (ret != 0) From e6398998b1863f69b7cd5665a4ed6e515fbb0eb5 Mon Sep 17 00:00:00 2001 From: kaleb-himes Date: Mon, 4 Jan 2016 12:55:35 -0700 Subject: [PATCH 2/3] check for NULL after malloc in posix_memalign --- wolfssl/test.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/wolfssl/test.h b/wolfssl/test.h index ebe722432..1e4fa1373 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -1374,7 +1374,7 @@ typedef THREAD_RETURN WOLFSSL_THREAD (*thread_func)(void* args); static INLINE void StackSizeCheck(func_args* args, thread_func tf) { int ret, i, used; - unsigned char* myStack = NULL; + unsigned char* myStack; int stackSize = 1024*128; pthread_attr_t myAttr; pthread_t threadId; @@ -1385,14 +1385,11 @@ static INLINE void StackSizeCheck(func_args* args, thread_func tf) #endif ret = posix_memalign((void**)&myStack, sysconf(_SC_PAGESIZE), stackSize); - if (ret != 0) + if (ret != 0 || myStack == NULL) err_sys("posix_memalign failed\n"); XMEMSET(myStack, 0x01, stackSize); - if (myStack == NULL) - err_sys("Failed to initialize myStack"); - ret = pthread_attr_init(&myAttr); if (ret != 0) err_sys("attr_init failed"); From 15918ebd99fd6c834572da79d6936f08391b1d1c Mon Sep 17 00:00:00 2001 From: kaleb-himes Date: Mon, 4 Jan 2016 13:18:43 -0700 Subject: [PATCH 3/3] initialize myStack to NULL for the later check against NULL --- wolfssl/test.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wolfssl/test.h b/wolfssl/test.h index 1e4fa1373..a0d1719e1 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -1374,7 +1374,7 @@ typedef THREAD_RETURN WOLFSSL_THREAD (*thread_func)(void* args); static INLINE void StackSizeCheck(func_args* args, thread_func tf) { int ret, i, used; - unsigned char* myStack; + unsigned char* myStack = NULL; int stackSize = 1024*128; pthread_attr_t myAttr; pthread_t threadId;