Skip to content

Commit

Permalink
Add remap needed null check (#711)
Browse files Browse the repository at this point in the history
* Add needed extra null check
* Add test for added check
* Add tests for nullptrs

Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>
  • Loading branch information
Blast545 authored Jul 20, 2020
1 parent c499108 commit 966efa3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions rcl/src/rcl/remap.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ rcl_remap_copy(
{
RCL_CHECK_ARGUMENT_FOR_NULL(rule, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(rule_out, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(rule->impl, RCL_RET_INVALID_ARGUMENT);

if (NULL != rule_out->impl) {
RCL_SET_ERROR_MSG("rule_out must be zero initialized");
Expand Down
11 changes: 11 additions & 0 deletions rcl/test/rcl/test_remap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,17 @@ TEST_F(CLASSNAME(TestRemapFixture, RMW_IMPLEMENTATION), internal_remap_use) {
EXPECT_EQ(RCL_RET_BAD_ALLOC, rcl_remap_copy(parsed_args.impl->remap_rules, &remap_dst));
parsed_args.impl->remap_rules->impl->allocator = alloc;

// Not valid null ptrs
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_remap_copy(nullptr, &remap_dst));
rcl_reset_error();
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_remap_copy(parsed_args.impl->remap_rules, nullptr));
rcl_reset_error();

// Not valid empty source
rcl_remap_t remap_empty = rcl_get_zero_initialized_remap();
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_remap_copy(&remap_empty, &remap_dst));
rcl_reset_error();

// Expected usage
EXPECT_EQ(RCL_RET_OK, rcl_remap_copy(parsed_args.impl->remap_rules, &remap_dst));

Expand Down

0 comments on commit 966efa3

Please sign in to comment.