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

LoRaWAN cppcheck warnings / bugs #1018

Closed
bertrik opened this issue Mar 16, 2024 · 5 comments · Fixed by #1017 or #1019
Closed

LoRaWAN cppcheck warnings / bugs #1018

bertrik opened this issue Mar 16, 2024 · 5 comments · Fixed by #1017 or #1019
Labels
bug Something isn't working resolved Issue was resolved (e.g. bug fixed, or feature implemented)

Comments

@bertrik
Copy link

bertrik commented Mar 16, 2024

When running the code checker tool 'cppcheck' on the LoRaWAN code, several warnings and style issues are produced. Some (most?) of these are probably false positives, but there are also some things that look like genuine bugs.

The bug
In particular, it warns about a for-loop in https://github.com/jgromes/RadioLib/blob/master/src/protocols/LoRaWAN/LoRaWAN.cpp#L2834
for(uint8_t j = 0; j < 8; i++) {

This for-loop looks like a simple 8-time iteration, except it increments variable i while it checks variable j.
This looks like a simple copy-paste error, and might result in an infinite loop or hang.

To Reproduce
install cppcheck, e.g. using your distribution's package manager
enter directory RadioLib/src/protocols/LoRaWAN and run
cppcheck *.cpp --enable=all

Expected behavior
No warnings about 'is always true', 'shadow variable', 'assigned a value that is never used', etc.

@StevenCellist
Copy link
Collaborator

Hey @bertrik, cool to see you here and nice catch! Will include in #1017. Fortunately, we don't often see that channel mask happening, but even worse would be the result because we'd hardly ever catch it...
As soon as #1017 compiles, please feel free to run your checker on it as well and notify me of potential problems.

@jgromes
Copy link
Owner

jgromes commented Mar 17, 2024

Strange that the CodeQL action (https://github.com/jgromes/RadioLib/actions/runs/8311068463) did not find such an obvious problem. IT also seems that I ahve missed the deprecation notice.

I will add cppcheck as a separate CI job.

jgromes added a commit that referenced this issue Mar 17, 2024
@jgromes jgromes linked a pull request Mar 17, 2024 that will close this issue
@jgromes
Copy link
Owner

jgromes commented Mar 17, 2024

The action is in, here's the output when scanning all RadioLib sources: https://github.com/jgromes/RadioLib/actions/runs/8313947188/job/22750505703?pr=1019

There's one error which seems like a bug in cppcheck itself (https://trac.cppcheck.net/ticket/11023), and most of the warnings are due to incorrect printf format specifiers.

@bertrik strangely enough, it does not find the loop you did - did you do any extra configuration? Also, which cppcheck verrsion are you using?

@bertrik
Copy link
Author

bertrik commented Mar 17, 2024

I ran:
cppcheck *.cpp --enable=all
in the LoRaWAN directory.

My cppcheck version is Cppcheck 2.13.0

I know from experience that code scanning tools can be a mixed blessing.
In this case, the problem only becomes visible at the more elaborate check level, giving warnings about harmless things too.
Before you know, you're fixing non-issues / investigating code-scanning tool bugs / putting a lot of effort in suppressing false positives / accidentally introducing actual bugs trying to silence a warning, etc.

jgromes added a commit that referenced this issue Mar 17, 2024
* Update CodeQL action

* [CI] Added workflow dispatch for codeql

* [CI] Use v4 checkout action

* [CI] Add cppcheck action (#1018)
@jgromes jgromes reopened this Mar 17, 2024
@jgromes
Copy link
Owner

jgromes commented Mar 17, 2024

I know from experience that code scanning tools can be a mixed blessing.

I'm painfully aware of that. That's why I didn't add any logic to the code scan CI that would trigger a job failure when something is detected.

I will leave this issue open until the PR fixing this is merged.

jgromes pushed a commit that referenced this issue Mar 18, 2024
* [LoRaWAN] Change and upgrade persistence handling

* [BuildOpt] Patch to upstream

* [LoRaWAN] Fix #1018

* [LoRaWAN] Remove outdated parts

* [LoRaWAN] Resolve feedback

Warning: untested - am not at my desk

* [LoRaWAN] Small bugfixes
@StevenCellist StevenCellist added the resolved Issue was resolved (e.g. bug fixed, or feature implemented) label Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resolved Issue was resolved (e.g. bug fixed, or feature implemented)
Projects
None yet
3 participants