Skip to content

Commit

Permalink
Merge pull request #55 from LnnrtS/topic-50
Browse files Browse the repository at this point in the history
Messages of message_queue need to be at least the size of a pointer.
  • Loading branch information
ilg-ul authored Oct 6, 2020
2 parents a6b4410 + 63655cd commit 9508c96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/cmsis-plus/rtos/os-mqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,8 @@ namespace os
const char* name, const attributes& attr) :
message_queue (name)
{
static_assert(sizeof(T) >= sizeof(void*), "Messages of message_queue need to have at least the size of a pointer");

internal_construct_ (msgs, sizeof(value_type), attr, &arena_,
sizeof(arena_));
}
Expand Down
4 changes: 4 additions & 0 deletions src/rtos/os-mqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,10 @@ namespace os
assert(msg_size_bytes_ == msg_size_bytes);
assert(msg_size_bytes_ > 0);

// in order for the list of free messages to not consume additional memory,
// the pointers are stored at the beginning of the messages, thus messages should be large enough to fit a pointer
assert(msg_size_bytes_ >= sizeof(void*));

msgs_ = static_cast<message_queue::size_t> (msgs);
assert(msgs_ == msgs);
assert(msgs > 0);
Expand Down

0 comments on commit 9508c96

Please sign in to comment.