From 14b7ca78d1e13b8fff1fabcdb55bfd90e60554ab Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 21 Oct 2016 14:43:25 -0500 Subject: [PATCH] Adopted MBED_STATIC_ASSERT where possible --- events/equeue/equeue_mbed.cpp | 9 ++++++--- features/netsocket/NetworkStack.cpp | 3 ++- platform/Callback.h | 18 ++++++++++++------ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/events/equeue/equeue_mbed.cpp b/events/equeue/equeue_mbed.cpp index 00f125d1b3..0e76c43a15 100644 --- a/events/equeue/equeue_mbed.cpp +++ b/events/equeue/equeue_mbed.cpp @@ -38,8 +38,10 @@ static void equeue_tick_update() { } static void equeue_tick_init() { - MBED_ASSERT(sizeof(equeue_timer) >= sizeof(Timer)); - MBED_ASSERT(sizeof(equeue_ticker) >= sizeof(Ticker)); + MBED_STATIC_ASSERT(sizeof(equeue_timer) >= sizeof(Timer), + "The equeue_timer buffer must fit the class Timer"); + MBED_STATIC_ASSERT(sizeof(equeue_ticker) >= sizeof(Ticker), + "The equeue_ticker buffer must fit the class Ticker"); new (equeue_timer) Timer; new (equeue_ticker) Ticker; @@ -78,7 +80,8 @@ void equeue_mutex_unlock(equeue_mutex_t *m) { #ifdef MBED_CONF_RTOS_PRESENT int equeue_sema_create(equeue_sema_t *s) { - MBED_ASSERT(sizeof(equeue_sema_t) >= sizeof(Semaphore)); + MBED_STATIC_ASSERT(sizeof(equeue_sema_t) >= sizeof(Semaphore), + "The equeue_sema_t must fit the class Semaphore"); new (s) Semaphore(0); return 0; } diff --git a/features/netsocket/NetworkStack.cpp b/features/netsocket/NetworkStack.cpp index ce20014a9d..5bfebff1d7 100644 --- a/features/netsocket/NetworkStack.cpp +++ b/features/netsocket/NetworkStack.cpp @@ -281,7 +281,8 @@ protected: // Conversion function for network stacks NetworkStack *nsapi_create_stack(nsapi_stack_t *stack) { - MBED_ASSERT(sizeof stack->_stack_buffer >= sizeof(NetworkStackWrapper)); + MBED_STATIC_ASSERT(sizeof stack->_stack_buffer >= sizeof(NetworkStackWrapper), + "The nsapi_stack_t stack buffer must fit a NetworkStackWrapper"); return new (stack->_stack_buffer) NetworkStackWrapper; } diff --git a/platform/Callback.h b/platform/Callback.h index d99b002dfb..d76e32be64 100644 --- a/platform/Callback.h +++ b/platform/Callback.h @@ -715,7 +715,8 @@ private: &Callback::function_dtor, }; - MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F)); + MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F), + "Type F must not exceed the size of the Callback class"); new (this) F(f); _ops = &ops; } @@ -1421,7 +1422,8 @@ private: &Callback::function_dtor, }; - MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F)); + MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F), + "Type F must not exceed the size of the Callback class"); new (this) F(f); _ops = &ops; } @@ -2127,7 +2129,8 @@ private: &Callback::function_dtor, }; - MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F)); + MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F), + "Type F must not exceed the size of the Callback class"); new (this) F(f); _ops = &ops; } @@ -2833,7 +2836,8 @@ private: &Callback::function_dtor, }; - MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F)); + MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F), + "Type F must not exceed the size of the Callback class"); new (this) F(f); _ops = &ops; } @@ -3539,7 +3543,8 @@ private: &Callback::function_dtor, }; - MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F)); + MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F), + "Type F must not exceed the size of the Callback class"); new (this) F(f); _ops = &ops; } @@ -4245,7 +4250,8 @@ private: &Callback::function_dtor, }; - MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F)); + MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F), + "Type F must not exceed the size of the Callback class"); new (this) F(f); _ops = &ops; }