Skip to content

Compile Flag Fixes - #276

Closed
jpsamper2009 wants to merge 1 commit into
ros2:masterfrom
ApexAI:compile-flag-fixes
Closed

jpsamper2009 wants to merge 1 commit into
ros2:masterfrom
ApexAI:compile-flag-fixes

Conversation

@jpsamper2009

@jpsamper2009 jpsamper2009 commented Aug 9, 2018 •

Copy link
Copy Markdown

Description

  • Courtesy of @serge-nikulin
  • This PR fixes warning generated when building with:
-Wall
-Wextra
-pedantic
-Wcast-align
-Wunused
-Wconversion
-Wsign-conversion
-Wdouble-promotion
-fvisibility=hidden

connects to ros2/rcutils#114

@esteve esteve added the in review Waiting for review (Kanban column) label Aug 9, 2018
@esteve esteve removed the in review Waiting for review (Kanban column) label Aug 20, 2018
@esteve

esteve commented Aug 20, 2018

Copy link
Copy Markdown
Member

I don't know why GitHub says I added the "in review" label, I don't recall doing that. Could it be something waffle did by itself? Anyway, I've removed the label from here and the other two pull requests.

@mikaelarguedas mikaelarguedas added the in review Waiting for review (Kanban column) label Aug 20, 2018
@mikaelarguedas

Copy link
Copy Markdown
Member

Yes it looks like waffle picks your account sometimes to set labels.

All 3rd party contributions come in review by default to not get lost in the backlog. So I added back the label on all 3 PRs

Thanks for monitoring though !

Comment thread rcl/src/rcl/arguments.c
RCL_CHECK_ARGUMENT_FOR_NULL(parameter_files, RCL_RET_INVALID_ARGUMENT, allocator);
*(parameter_files) = allocator.allocate(
sizeof(char *) * arguments->impl->num_param_files_args, allocator.state);
sizeof(char *) * (size_t)arguments->impl->num_param_files_args, allocator.state);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, it looks like num_params_files_args (https://github.com/ros2/rcl/blob/master/rcl/src/rcl/arguments_impl.h#L38) is always used as an unsigned number (which makes sense, since it is the "number" of things). Thus, I'd suggest that we actually change the type in the structure, rather than casting it here (in a quick test I did here, that seems to be OK).

Comment thread rcl/src/rcl/arguments.c
if (args_impl->num_remap_rules > 0) {
args_impl->remap_rules = rcutils_reallocf(
args_impl->remap_rules, sizeof(rcl_remap_t) * args_impl->num_remap_rules, &allocator);
args_impl->remap_rules, sizeof(rcl_remap_t) * (size_t)args_impl->num_remap_rules, &allocator);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, it looks like num_remap_rules could probably be a size_t in the structure, rather than doing this cast.

Comment thread rcl/src/rcl/arguments.c
if (args->impl->num_unparsed_args) {
*output_unparsed_indices = allocator.allocate(
sizeof(int) * args->impl->num_unparsed_args, allocator.state);
sizeof(int) * (size_t)args->impl->num_unparsed_args, allocator.state);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the same for num_unparsed_args.

Comment thread rcl/src/rcl/time.c
return rcl_get_system_time(data, current_time);
}
*current_time = rcl_atomic_load_uint64_t(&(t->current_time));
*current_time = (rcl_time_point_value_t)rcl_atomic_load_uint64_t(&(t->current_time));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmpf, I can't say I love this. If we look carefully at the types, t->current_time is of type atomic_uint_least64_t (https://github.com/ros2/rcl/blob/master/rcl/src/rcl/time.c#L30). rcl_atomic_load_uint64_t expects a uint64 argument expects an atomic_uint_least64_t pointer as the input argument, so we are good so far. Then rcl_atomic_load_uint64_t returns a uint64_t (https://github.com/ros2/rcl/blob/master/rcl/src/rcl/stdatomic_helper.h#L72), and here we get into trouble. The next thing we are going to do is to store this into *current_time which is rcl_time_point_value_t -> rcutils_time_point_value_t -> int64_t. So now we are storing an unsigned into a signed, potentially changing the interpretation. I'm not sure how much it matters in this case since it is a 64-bit load, but this doesn't seem quite right. @tfoote , any thoughts on this?

Comment thread rcl/src/rcl/time.c
clock->pre_update();
}
rcl_atomic_store(&(storage->current_time), time_value);
rcl_atomic_store(&(storage->current_time), (uint64_t)time_value);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is the same int64/uint64 mismatch.

Comment thread rcl/src/rcl/timer.c
atomic_init(&impl.period, period);
atomic_init(&impl.last_call_time, now);
atomic_init(&impl.period, (unint64_t)(period));
atomic_init(&impl.last_call_time, (unit64_t)(now));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And again, these casts are needed because this is a type mismatch. There may more down below, but I'm going to stop there. In general I think it is a better idea to look at and think about why the cast is needed, and try to fix the root cause. I know it is not always possible because some of the types are pre-defined for us, but for the types we do have control of it is better to use consistent types.

@clalancette

Copy link
Copy Markdown
Contributor

@jpsamper2009 Friendly ping. Do you think you'll have time to pick this and ros2/rcutils#114 back up? Thanks.

@mabelzhang mabelzhang removed the in review Waiting for review (Kanban column) label Sep 19, 2019
@jpsamper2009

jpsamper2009 commented Sep 20, 2019 •

Copy link
Copy Markdown
Author

@clalancette This PR was a for a much older version of the code -- and it was done by me on behalf of someone else. I'll close it and readdress with a newer version (if the issues still exist). Sorry for the long wait.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants