Skip to content

Commit

Permalink
Merge pull request ros2#16 from ros2/fix_warnings
Browse files Browse the repository at this point in the history
Fix warnings
  • Loading branch information
wjwwood committed Jan 6, 2016
2 parents 004698a + 3310359 commit 0fd8b01
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 47 deletions.
11 changes: 7 additions & 4 deletions rcl/src/rcl/wait.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,19 @@ __wait_set_is_valid(const rcl_wait_set_t * wait_set)
static void
__wait_set_clean_up(rcl_wait_set_t * wait_set, rcl_allocator_t allocator)
{
rcl_ret_t ret;
if (wait_set->subscriptions) {
ret = rcl_wait_set_resize_subscriptions(wait_set, 0);
rcl_ret_t ret = rcl_wait_set_resize_subscriptions(wait_set, 0);
(void)ret; // NO LINT
assert(ret == RCL_RET_OK); // Defensive, shouldn't fail with size 0.
}
if (wait_set->guard_conditions) {
ret = rcl_wait_set_resize_guard_conditions(wait_set, 0);
rcl_ret_t ret = rcl_wait_set_resize_guard_conditions(wait_set, 0);
(void)ret; // NO LINT
assert(ret == RCL_RET_OK); // Defensive, shouldn't fail with size 0.
}
if (wait_set->timers) {
ret = rcl_wait_set_resize_timers(wait_set, 0);
rcl_ret_t ret = rcl_wait_set_resize_timers(wait_set, 0);
(void)ret; // NO LINT
assert(ret == RCL_RET_OK); // Defensive, shouldn't fail with size 0.
}
if (wait_set->impl) {
Expand Down Expand Up @@ -429,6 +431,7 @@ rcl_wait(rcl_wait_set_t * wait_set, int64_t timeout)
if (ret == RMW_RET_TIMEOUT) {
// Assume none were set (because timeout was reached first), and clear all.
rcl_ret_t rcl_ret;
(void)rcl_ret; // NO LINT
rcl_ret = rcl_wait_set_clear_subscriptions(wait_set);
assert(rcl_ret == RCL_RET_OK); // Defensive, shouldn't fail with valid wait_set.
rcl_ret = rcl_wait_set_clear_guard_conditions(wait_set);
Expand Down
10 changes: 5 additions & 5 deletions rcl/test/rcl/test_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ TEST_F(TestAllocatorFixture, test_default_allocator_normal) {
assert_no_realloc_begin();
assert_no_free_begin();
void * allocated_memory = allocator.allocate(1024, allocator.state);
EXPECT_EQ(mallocs, 1);
EXPECT_EQ(mallocs, 1u);
EXPECT_NE(allocated_memory, nullptr);
allocated_memory = allocator.reallocate(allocated_memory, 2048, allocator.state);
EXPECT_EQ(reallocs, 1);
EXPECT_EQ(reallocs, 1u);
EXPECT_NE(allocated_memory, nullptr);
allocator.deallocate(allocated_memory, allocator.state);
EXPECT_EQ(mallocs, 1);
EXPECT_EQ(reallocs, 1);
EXPECT_EQ(frees, 1);
EXPECT_EQ(mallocs, 1u);
EXPECT_EQ(reallocs, 1u);
EXPECT_EQ(frees, 1u);
}
12 changes: 6 additions & 6 deletions rcl/test/rcl/test_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ TEST_F(TestNodeFixture, test_rcl_node_accessors) {
EXPECT_EQ(RCL_RET_OK, ret);
if (RCL_RET_OK == ret && (!is_windows || !is_opensplice)) {
// Can only expect the domain id to be 42 if not windows or not opensplice.
EXPECT_EQ(42, actual_domain_id);
EXPECT_EQ(42u, actual_domain_id);
}
// Test rcl_node_get_rmw_handle().
rmw_node_t * node_handle;
Expand All @@ -227,14 +227,14 @@ TEST_F(TestNodeFixture, test_rcl_node_accessors) {
// Test rcl_node_get_rcl_instance_id().
uint64_t instance_id;
instance_id = rcl_node_get_rcl_instance_id(nullptr);
EXPECT_EQ(0, instance_id);
EXPECT_EQ(0u, instance_id);
rcl_reset_error();
instance_id = rcl_node_get_rcl_instance_id(&zero_node);
EXPECT_EQ(0, instance_id);
EXPECT_EQ(0u, instance_id);
rcl_reset_error();
instance_id = rcl_node_get_rcl_instance_id(&invalid_node);
EXPECT_NE(0, instance_id);
EXPECT_NE(42, instance_id);
EXPECT_NE(0u, instance_id);
EXPECT_NE(42u, instance_id);
rcl_reset_error();
start_memory_checking();
assert_no_malloc_begin();
Expand All @@ -245,7 +245,7 @@ TEST_F(TestNodeFixture, test_rcl_node_accessors) {
assert_no_realloc_end();
assert_no_free_end();
stop_memory_checking();
EXPECT_NE(0, instance_id);
EXPECT_NE(0u, instance_id);
}

/* Tests the node life cycle, including rcl_node_init() and rcl_node_fini().
Expand Down
12 changes: 6 additions & 6 deletions rcl/test/rcl/test_rcl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ TEST_F(TestRCLFixture, test_rcl_init_and_ok_and_shutdown) {
TEST_F(TestRCLFixture, test_rcl_get_instance_id_and_ok) {
rcl_ret_t ret;
// Instance id should be 0 before rcl_init().
EXPECT_EQ(0, rcl_get_instance_id());
EXPECT_EQ(0u, rcl_get_instance_id());
ASSERT_FALSE(rcl_ok());
// It should still return 0 after an invalid init.
ret = rcl_init(1, nullptr, rcl_get_default_allocator());
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret);
EXPECT_EQ(0, rcl_get_instance_id());
EXPECT_EQ(0u, rcl_get_instance_id());
ASSERT_FALSE(rcl_ok());
// A non-zero instance id should be returned after a valid init.
{
Expand All @@ -207,13 +207,13 @@ TEST_F(TestRCLFixture, test_rcl_get_instance_id_and_ok) {
assert_no_malloc_end();
assert_no_realloc_end();
assert_no_free_end();
EXPECT_NE(0, first_instance_id);
EXPECT_NE(0u, first_instance_id);
EXPECT_EQ(first_instance_id, rcl_get_instance_id()); // Repeat calls should return the same.
EXPECT_EQ(true, rcl_ok());
// Calling after a shutdown should return 0.
ret = rcl_shutdown();
EXPECT_EQ(ret, RCL_RET_OK);
EXPECT_EQ(0, rcl_get_instance_id());
EXPECT_EQ(0u, rcl_get_instance_id());
ASSERT_FALSE(rcl_ok());
// It should return a different value after another valid init.
{
Expand All @@ -222,12 +222,12 @@ TEST_F(TestRCLFixture, test_rcl_get_instance_id_and_ok) {
EXPECT_EQ(RCL_RET_OK, ret);
ASSERT_TRUE(rcl_ok());
}
EXPECT_NE(0, rcl_get_instance_id());
EXPECT_NE(0u, rcl_get_instance_id());
EXPECT_NE(first_instance_id, rcl_get_instance_id());
ASSERT_TRUE(rcl_ok());
// Shutting down a second time should result in 0 again.
ret = rcl_shutdown();
EXPECT_EQ(ret, RCL_RET_OK);
EXPECT_EQ(0, rcl_get_instance_id());
EXPECT_EQ(0u, rcl_get_instance_id());
ASSERT_FALSE(rcl_ok());
}
4 changes: 2 additions & 2 deletions rcl/test/rcl/test_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ TEST_F(TestTimeFixture, test_rcl_system_time_point_now) {
assert_no_free_end();
stop_memory_checking();
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string_safe();
EXPECT_NE(now.nanoseconds, 0);
EXPECT_NE(now.nanoseconds, 0u);
// Compare to std::chrono::system_clock time (within a second).
now = {0};
ret = rcl_system_time_point_now(&now);
Expand Down Expand Up @@ -99,7 +99,7 @@ TEST_F(TestTimeFixture, test_rcl_steady_time_point_now) {
assert_no_free_end();
stop_memory_checking();
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string_safe();
EXPECT_NE(now.nanoseconds, 0);
EXPECT_NE(now.nanoseconds, 0u);
// Compare to std::chrono::steady_clock difference of two times (within a second).
now = {0};
ret = rcl_steady_time_point_now(&now);
Expand Down
48 changes: 24 additions & 24 deletions rcl/test/test_memory_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ TEST(TestMemoryTools, test_allocation_checking_tools) {
ASSERT_NE(remem, nullptr);
if (!remem) {free(mem);}
free(remem);
EXPECT_EQ(unexpected_mallocs, 0);
EXPECT_EQ(unexpected_reallocs, 0);
EXPECT_EQ(unexpected_frees, 0);
EXPECT_EQ(unexpected_mallocs, 0u);
EXPECT_EQ(unexpected_reallocs, 0u);
EXPECT_EQ(unexpected_frees, 0u);
// Enable checking, but no assert, should have no effect.
start_memory_checking();
mem = malloc(1024);
Expand All @@ -54,9 +54,9 @@ TEST(TestMemoryTools, test_allocation_checking_tools) {
ASSERT_NE(remem, nullptr);
if (!remem) {free(mem);}
free(remem);
EXPECT_EQ(unexpected_mallocs, 0);
EXPECT_EQ(unexpected_reallocs, 0);
EXPECT_EQ(unexpected_frees, 0);
EXPECT_EQ(unexpected_mallocs, 0u);
EXPECT_EQ(unexpected_reallocs, 0u);
EXPECT_EQ(unexpected_frees, 0u);
// Enable no_* asserts, should increment all once.
assert_no_malloc_begin();
assert_no_realloc_begin();
Expand All @@ -70,9 +70,9 @@ TEST(TestMemoryTools, test_allocation_checking_tools) {
if (!remem) {free(mem);}
free(remem);
assert_no_free_end();
EXPECT_EQ(unexpected_mallocs, 1);
EXPECT_EQ(unexpected_reallocs, 1);
EXPECT_EQ(unexpected_frees, 1);
EXPECT_EQ(unexpected_mallocs, 1u);
EXPECT_EQ(unexpected_reallocs, 1u);
EXPECT_EQ(unexpected_frees, 1u);
// Enable on malloc assert, only malloc should increment.
assert_no_malloc_begin();
mem = malloc(1024);
Expand All @@ -82,9 +82,9 @@ TEST(TestMemoryTools, test_allocation_checking_tools) {
ASSERT_NE(remem, nullptr);
if (!remem) {free(mem);}
free(remem);
EXPECT_EQ(unexpected_mallocs, 2);
EXPECT_EQ(unexpected_reallocs, 1);
EXPECT_EQ(unexpected_frees, 1);
EXPECT_EQ(unexpected_mallocs, 2u);
EXPECT_EQ(unexpected_reallocs, 1u);
EXPECT_EQ(unexpected_frees, 1u);
// Enable on realloc assert, only realloc should increment.
assert_no_realloc_begin();
mem = malloc(1024);
Expand All @@ -94,9 +94,9 @@ TEST(TestMemoryTools, test_allocation_checking_tools) {
ASSERT_NE(remem, nullptr);
if (!remem) {free(mem);}
free(remem);
EXPECT_EQ(unexpected_mallocs, 2);
EXPECT_EQ(unexpected_reallocs, 2);
EXPECT_EQ(unexpected_frees, 1);
EXPECT_EQ(unexpected_mallocs, 2u);
EXPECT_EQ(unexpected_reallocs, 2u);
EXPECT_EQ(unexpected_frees, 1u);
// Enable on free assert, only free should increment.
assert_no_free_begin();
mem = malloc(1024);
Expand All @@ -106,19 +106,19 @@ TEST(TestMemoryTools, test_allocation_checking_tools) {
if (!remem) {free(mem);}
free(remem);
assert_no_free_end();
EXPECT_EQ(unexpected_mallocs, 2);
EXPECT_EQ(unexpected_reallocs, 2);
EXPECT_EQ(unexpected_frees, 2);
EXPECT_EQ(unexpected_mallocs, 2u);
EXPECT_EQ(unexpected_reallocs, 2u);
EXPECT_EQ(unexpected_frees, 2u);
// Go again, after disabling asserts, should have no effect.
mem = malloc(1024);
ASSERT_NE(mem, nullptr);
remem = realloc(mem, 2048);
ASSERT_NE(remem, nullptr);
if (!remem) {free(mem);}
free(remem);
EXPECT_EQ(unexpected_mallocs, 2);
EXPECT_EQ(unexpected_reallocs, 2);
EXPECT_EQ(unexpected_frees, 2);
EXPECT_EQ(unexpected_mallocs, 2u);
EXPECT_EQ(unexpected_reallocs, 2u);
EXPECT_EQ(unexpected_frees, 2u);
// Go once more after disabling everything, should have no effect.
stop_memory_checking();
mem = malloc(1024);
Expand All @@ -127,7 +127,7 @@ TEST(TestMemoryTools, test_allocation_checking_tools) {
ASSERT_NE(remem, nullptr);
if (!remem) {free(mem);}
free(remem);
EXPECT_EQ(unexpected_mallocs, 2);
EXPECT_EQ(unexpected_reallocs, 2);
EXPECT_EQ(unexpected_frees, 2);
EXPECT_EQ(unexpected_mallocs, 2u);
EXPECT_EQ(unexpected_reallocs, 2u);
EXPECT_EQ(unexpected_frees, 2u);
}

0 comments on commit 0fd8b01

Please sign in to comment.