Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra check for invalid event implementation #726

Merged
merged 3 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions rcl/src/rcl/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ rcl_take_event(
void * event_info)
{
bool taken = false;
RCL_CHECK_ARGUMENT_FOR_NULL(event, RCL_RET_EVENT_INVALID);
if (!rcl_event_is_valid(event)) {
return RCL_RET_EVENT_INVALID;
}
RCL_CHECK_ARGUMENT_FOR_NULL(event_info, RCL_RET_INVALID_ARGUMENT);
rmw_ret_t ret = rmw_take_event(&event->impl->rmw_handle, event_info, &taken);
if (RMW_RET_OK != ret) {
Expand Down Expand Up @@ -179,7 +181,7 @@ rcl_event_fini(rcl_event_t * event)
rmw_event_t *
rcl_event_get_rmw_handle(const rcl_event_t * event)
{
if (NULL == event) {
if (!rcl_event_is_valid(event)) {
return NULL; // error already set
Blast545 marked this conversation as resolved.
Show resolved Hide resolved
} else {
return &event->impl->rmw_handle;
Expand Down
23 changes: 15 additions & 8 deletions rcl/test/rcl/test_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,6 @@ TEST_F(TestEventFixture, test_bad_event_ini)
tear_down_publisher_subscriber();
}

/*
* Passing bad argument to get_rmw_handle
*/
TEST_F(TestEventFixture, test_bad_get_handle)
{
EXPECT_EQ(NULL, rcl_event_get_rmw_handle(NULL));
}

/*
* Test cases for the event_is_valid function
*/
Expand Down Expand Up @@ -773,6 +765,21 @@ TEST_F(TestEventFixture, test_event_is_valid)
tear_down_publisher_subscriber();
}

/*
* Test passing not init to take_event/get_handle
*/
TEST_F(TestEventFixture, test_event_is_invalid) {
// nullptr
rmw_offered_deadline_missed_status_t deadline_status;
EXPECT_EQ(RCL_RET_EVENT_INVALID, rcl_take_event(NULL, &deadline_status));
EXPECT_EQ(NULL, rcl_event_get_rmw_handle(NULL));

// Zero Init, invalid
rcl_event_t publisher_event_test = rcl_get_zero_initialized_event();
EXPECT_EQ(RCL_RET_EVENT_INVALID, rcl_take_event(&publisher_event_test, &deadline_status));
EXPECT_EQ(NULL, rcl_event_get_rmw_handle(&publisher_event_test));
}

/*
* Basic test subscriber event message lost
*/
Expand Down