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

cppcheck warning due to if (true) inside while (true) #157

Closed
armandas opened this issue Mar 15, 2019 · 4 comments
Closed

cppcheck warning due to if (true) inside while (true) #157

armandas opened this issue Mar 15, 2019 · 4 comments

Comments

@armandas
Copy link

The following code in lfs.c causes a cppcheck warning

Identical inner 'if' condition is always true (outer condition is 'true' and inner condition is 'true').

    // begin loop to commit compaction to blocks until a compact sticks
    while (true) {
        if (true) {

if (true) appears in several places in littlefs. Is this done for debugging purposes or some other reasons? Is it possible to change the implementation to avoid the warning?

@geky
Copy link
Member

geky commented Apr 1, 2019

The if (true) { is to avoid a warning about goto bypassing variable initialization. If you replace it with just { does the warning go away?

@armandas
Copy link
Author

armandas commented Apr 2, 2019

I did not get any compiler warnings with or without if (true) { (only error: redefinition of 'err'). The error does not happen when if (true) { is replaced by {.

I am using GCC for ARM, V6.3.1.

@geky
Copy link
Member

geky commented Apr 9, 2019

Thanks for raising an issue, I pushed up a fix on the v2-alpha branch (#85).

Related #155

@armandas
Copy link
Author

Thank you. I can confirm that the cppcheck warnings are gone.

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

No branches or pull requests

2 participants