Skip to content

Commit 98db3ab

Browse files
committed
Adopted MBED_STATIC_ASSERT where possible
1 parent 182c6a2 commit 98db3ab

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

events/equeue/equeue_mbed.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ static void equeue_tick_update() {
3838
}
3939

4040
static void equeue_tick_init() {
41-
MBED_ASSERT(sizeof(equeue_timer) >= sizeof(Timer));
42-
MBED_ASSERT(sizeof(equeue_ticker) >= sizeof(Ticker));
41+
MBED_STATIC_ASSERT(sizeof(equeue_timer) >= sizeof(Timer),
42+
"The equeue_timer buffer must fit the class Timer");
43+
MBED_STATIC_ASSERT(sizeof(equeue_ticker) >= sizeof(Ticker),
44+
"The equeue_ticker buffer must fit the class Ticker");
4345
new (equeue_timer) Timer;
4446
new (equeue_ticker) Ticker;
4547

@@ -78,7 +80,8 @@ void equeue_mutex_unlock(equeue_mutex_t *m) {
7880
#ifdef MBED_CONF_RTOS_PRESENT
7981

8082
int equeue_sema_create(equeue_sema_t *s) {
81-
MBED_ASSERT(sizeof(equeue_sema_t) >= sizeof(Semaphore));
83+
MBED_STATIC_ASSERT(sizeof(equeue_sema_t) >= sizeof(Semaphore),
84+
"The equeue_sema_t must fit the class Semaphore");
8285
new (s) Semaphore(0);
8386
return 0;
8487
}

features/netsocket/NetworkStack.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ class NetworkStackWrapper : public NetworkStack
294294
// Conversion function for network stacks
295295
NetworkStack *nsapi_create_stack(nsapi_stack_t *stack)
296296
{
297-
MBED_ASSERT(sizeof stack->_stack_buffer >= sizeof(NetworkStackWrapper));
297+
MBED_STATIC_ASSERT(sizeof stack->_stack_buffer >= sizeof(NetworkStackWrapper),
298+
"The nsapi_stack_t stack buffer must fit a NetworkStackWrapper");
298299
return new (stack->_stack_buffer) NetworkStackWrapper;
299300
}
300301

platform/Callback.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,8 @@ class Callback<R()> {
715715
&Callback::function_dtor<F>,
716716
};
717717

718-
MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F));
718+
MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
719+
"Type F must not exceed the size of the Callback class");
719720
new (this) F(f);
720721
_ops = &ops;
721722
}
@@ -1421,7 +1422,8 @@ class Callback<R(A0)> {
14211422
&Callback::function_dtor<F>,
14221423
};
14231424

1424-
MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F));
1425+
MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
1426+
"Type F must not exceed the size of the Callback class");
14251427
new (this) F(f);
14261428
_ops = &ops;
14271429
}
@@ -2127,7 +2129,8 @@ class Callback<R(A0, A1)> {
21272129
&Callback::function_dtor<F>,
21282130
};
21292131

2130-
MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F));
2132+
MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
2133+
"Type F must not exceed the size of the Callback class");
21312134
new (this) F(f);
21322135
_ops = &ops;
21332136
}
@@ -2833,7 +2836,8 @@ class Callback<R(A0, A1, A2)> {
28332836
&Callback::function_dtor<F>,
28342837
};
28352838

2836-
MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F));
2839+
MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
2840+
"Type F must not exceed the size of the Callback class");
28372841
new (this) F(f);
28382842
_ops = &ops;
28392843
}
@@ -3539,7 +3543,8 @@ class Callback<R(A0, A1, A2, A3)> {
35393543
&Callback::function_dtor<F>,
35403544
};
35413545

3542-
MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F));
3546+
MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
3547+
"Type F must not exceed the size of the Callback class");
35433548
new (this) F(f);
35443549
_ops = &ops;
35453550
}
@@ -4245,7 +4250,8 @@ class Callback<R(A0, A1, A2, A3, A4)> {
42454250
&Callback::function_dtor<F>,
42464251
};
42474252

4248-
MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F));
4253+
MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
4254+
"Type F must not exceed the size of the Callback class");
42494255
new (this) F(f);
42504256
_ops = &ops;
42514257
}

0 commit comments

Comments
 (0)