-
Couldn't load subscription status.
- Fork 932
Check for shadowing in lfs.c and ensure clean compilation #1150
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
base: master
Are you sure you want to change the base?
Check for shadowing in lfs.c and ensure clean compilation #1150
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming of the introduced variables doesn't really improve clarity per se.
A better approach would be checking which of these cases may actually allow to skip these additional variables and use the outer scoped one (safely). That way this would even improve on stack frame size.
Nothing against this PR (I'm all for enforcing -Wshadow, it's just that this currently doesn't look clean either … So more refinement might be good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated new test, that doesn't actually test anything in LittleFS.
| err1 = lfs_tortoise_detectcycles(pdir, &tortoise); | ||
| if (err1 < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inlining this check would eliminate the need for err1 entirely AFAICS.
| err1 = lfs_tortoise_detectcycles(pdir, &tortoise); | |
| if (err1 < 0) { | |
| if (lfs_tortoise_detectcycles(pdir, &tortoise) < 0) { |
| #include "lfs_util.h" | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated white space change.
| int err_traverse = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache, | ||
| f->ctz.head, f->ctz.size, cb, data); | ||
| if (err) { | ||
| if (err_traverse ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduces white space/formatting change.
| if (err_traverse ) { | |
| if (err_traverse) { |
| int err_traverse = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache, | ||
| f->ctz.head, f->ctz.size, cb, data); | ||
| if (err) { | ||
| if (err_traverse ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduces white space/formatting change.
| if (err_traverse ) { | |
| if (err_traverse) { |
|
|
||
| if ((f->flags & LFS_F_WRITING) && !(f->flags & LFS_F_INLINE)) { | ||
| int err = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache, | ||
| int err_traverse = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduces white space/formatting change.
| int err_traverse = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache, | |
| int err_traverse = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache, |
|
|
||
| if ((f->flags & LFS_F_WRITING) && !(f->flags & LFS_F_INLINE)) { | ||
| int err = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache, | ||
| int err_traverse = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduces white space/formatting change.
| int err_traverse = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache, | |
| int err_traverse = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache, |
| if (err_traverse ) { | ||
| return err_traverse ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduces white space/formatting change.
| if (err_traverse ) { | |
| return err_traverse ; | |
| if (err_traverse) { | |
| return err_traverse; |
|
Hi @DarukaThirumurugan, I appreciate the pull request, but IMO this is an unproductive warning and does more harm than good. See #873 and #873 (comment). |
Refactor: cleared variable shadowing in lfs.c
Identified and resolved instances of variable shadowing in lfs.c.
This improves code readability and reduces the risk of bugs
due to accidental re-use of variable names in inner scopes.
Used -Wshadow flag to detect issues and verified successful
compilation with no warnings.
In the original code there are many shadows occured as a warning
After Altering
There is no shadow occurs