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

Misra c round1 #91

Merged
merged 5 commits into from
Feb 16, 2018
Merged

Misra c round1 #91

merged 5 commits into from
Feb 16, 2018

Conversation

mikaelarguedas
Copy link
Member

@mikaelarguedas mikaelarguedas commented Feb 15, 2018

This addresses a subset of misra C violations in this package

/cc @dejanpan

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status (unrelated osrf_pycommon failures)
  • Windows Build Status (unrelated osrf_pycommon failures)

@mikaelarguedas mikaelarguedas added the in progress Actively being worked on (Kanban column) label Feb 15, 2018
@mikaelarguedas
Copy link
Member Author

Placing this in review and will run CI on OSX ASAP

@mikaelarguedas mikaelarguedas added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Feb 15, 2018
@mikaelarguedas
Copy link
Member Author

MacOS CI passed. ready for review

@mikaelarguedas mikaelarguedas merged commit 9acfe05 into master Feb 16, 2018
@mikaelarguedas mikaelarguedas deleted the misra_c_round1 branch February 16, 2018 22:59
@mikaelarguedas mikaelarguedas removed the in review Waiting for review (Kanban column) label Feb 16, 2018
@@ -219,7 +219,7 @@ rcutils_string_map_clear(rcutils_string_map_t * string_map)
return RCUTILS_RET_STRING_MAP_INVALID, rcutils_get_default_allocator())
size_t i = 0;
for (; i < string_map->impl->capacity; ++i) {
if (string_map->impl->keys[i]) {
if (string_map->impl->keys[i] != NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a question, I notice it's consistent about NULL == something for equality and something != NULL for inequality. Is the order of these a rule in misra C?

Copy link
Member Author

Choose a reason for hiding this comment

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

No that's not part of MISRA, but it's part of our design guildelines

Always place literals on the left hand side of comparison operators, e.g. 0 == ret instead of ret == 0

  • rationale: ret == 0 too easily turns into ret = 0 by accident

Copy link
Contributor

Choose a reason for hiding this comment

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

Is our rule for all comparison operators, or just ==? If the former then should this line be NULL != string_map->impl->keys[i])?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I guess that would be better.
My reading was that it's a lot less likely to write = instead of != and more likely to write = instead of == and that's what we apply everywhere else in the codebase. But I'm not opposed to apply the rule to all comparison operators and not only ==

Copy link
Contributor

Choose a reason for hiding this comment

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

!= becoming = seems a lot less likely. I'm not advocating changing anything, my question is answered by you saying it isn't part of Misra C

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants