Skip to content

dist/cppcheck: fix missing cppcheck-suppression reasons#10010

Merged
miri64 merged 4 commits intoRIOT-OS:masterfrom
smlng:pr/fix/cppcheck-suppress
Sep 25, 2018
Merged

dist/cppcheck: fix missing cppcheck-suppression reasons#10010
miri64 merged 4 commits intoRIOT-OS:masterfrom
smlng:pr/fix/cppcheck-suppress

Conversation

@smlng
Copy link
Copy Markdown
Member

@smlng smlng commented Sep 21, 2018

Contribution description

Fixes #1895

This adds or corrects missing rationale on existing cppcheck-suppression comments.

Testing procedure

run git grep -A1 cppcheck-suppression on master and review if the line below cppcheck-suppress <something> looks like * (reason: <explanation>) */ and compare with this PR, which should fix all mismatches.

Issues/PRs references

@smlng smlng added Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: tools Area: Supplementary tools labels Sep 21, 2018
@smlng smlng requested review from cladmi and miri64 September 21, 2018 08:59
Copy link
Copy Markdown
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

ACK and go when Murdock is happy

@miri64
Copy link
Copy Markdown
Member

miri64 commented Sep 21, 2018

Murdock isn't happy though (apparently there is another error in dist/tools/tunslip/tunslip6.c) and Travis also found another problem.

@smlng
Copy link
Copy Markdown
Member Author

smlng commented Sep 21, 2018

seems to be the old cppcheck versions in travis and murdock, my macOS cppcheck (version 1.84) is totally fine with all the changes.

@smlng
Copy link
Copy Markdown
Member Author

smlng commented Sep 25, 2018

@miri64 fixed travis and murdock complains, may I squash?

/* need to consider `\0` terminator and strlen("dev") = 5, hence 6
* cppcheck-suppress bufferAccessOutOfBounds
* (reason: seems to be a bug in cppcheck 1.7x) */
strncat(t, dev, sizeof(t) - 6);
Copy link
Copy Markdown
Member

@miri64 miri64 Sep 25, 2018

Choose a reason for hiding this comment

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

I think the comment on top is completely wrong (the tool obviously works without the fix). Anyway, this should rather go in a separate PR so it can be independently tested.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

just because it works, the comment is wrong?

Looking at http://www.cplusplus.com/reference/cstring/strncat/ it states that the destination must be large enough to include both strings plus the \0 terminator, so the calculation in the comment is correct, or not. One could rewrite this to sizeof(t) - (strlen(dev) + 1) to make it more obvious, but why bother to run strlen(dev) when we know its fixed to 5.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please let's discuss this in a separate PR. Regardless of right or wrong, this change does not belong here.

/* need to consider `\0` terminator and strlen("dev") = 5, hence 6
* cppcheck-suppress bufferAccessOutOfBounds
* (reason: seems to be a bug in cppcheck 1.7x) */
strncat(t, dev, sizeof(t) - 6);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

strange, I simply squashed and rebased, why was murdock happy before?

@smlng
Copy link
Copy Markdown
Member Author

smlng commented Sep 25, 2018

removed the controversy 😬 Both CI look happy, squash?

@smlng
Copy link
Copy Markdown
Member Author

smlng commented Sep 25, 2018

happy besides fixup commits, that is.

@miri64
Copy link
Copy Markdown
Member

miri64 commented Sep 25, 2018

Both CI look happy, squash?

Yes please!

Copy link
Copy Markdown
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

ACK

@smlng smlng force-pushed the pr/fix/cppcheck-suppress branch from 3e5e610 to a4ef4cc Compare September 25, 2018 09:38
@smlng
Copy link
Copy Markdown
Member Author

smlng commented Sep 25, 2018

to verify run git grep -A1 "/* cppcheck-suppress " and review the output, with this PR all places adhere to format:

/* cppcheck-suppress <CONDITION> 
 * (reason: <RATIONALE/COMMENT> */

so should resolve #1895

@miri64
Copy link
Copy Markdown
Member

miri64 commented Sep 25, 2018

Good point! Found one remaining tiny deviation ;-):

tests/cpp11_condition_variable/main.cpp:      /* cppcheck-suppress unreadVariable
tests/cpp11_condition_variable/main.cpp-       * (reason variable is read in the thread created above) */

Adding and correcting description/rational on why certain cppcheck
warnings or errors are intentionally suppressed.
Extend the cppcheck suppression example to show that each suppression
should have a reason describing the intentional suppression of a
cppcheck warning or error.
Cppcheck was (correctly) warning here that concat to strings might
result in buffer overflow because the terminating `\0` was not considered.
This is fixed here, making the cppcheck suppression also obsolete.
This was found by cppcheck 1.6x used in Travis-CI, however this
seems to be a false positive, as it is not found by newer versions
of cppcheck.
@smlng smlng force-pushed the pr/fix/cppcheck-suppress branch from a4ef4cc to 5b1cd04 Compare September 25, 2018 10:04
@smlng
Copy link
Copy Markdown
Member Author

smlng commented Sep 25, 2018

amended fix (colon) directly

@miri64
Copy link
Copy Markdown
Member

miri64 commented Sep 25, 2018

Thanks for finally tackling this!

@miri64 miri64 merged commit 5ac02f5 into RIOT-OS:master Sep 25, 2018
@smlng smlng deleted the pr/fix/cppcheck-suppress branch September 25, 2018 11:55
@jia200x jia200x added this to the Release 2018.10 milestone Oct 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cppcheck: add rationale to suppressed warnings

3 participants