Skip to content

Conversation

@elupus
Copy link
Contributor

@elupus elupus commented Mar 14, 2025

lfs_gstate_t was assumed to be a packed array of uint32_t, but this is not always guaranteed. Access the fields directly instead of attempting to loop over an array of uint32_t

Fixes clang tidy warnings about use of uninitialized memory accessed.

lfs_gstate_t was assumed to be a packed array of uint32_t,
but this is not always guaranteed. Access the fields directly
instead of attempting to loop over an array of uint32_t

Fixes clang tidy warnings about use of uninitialized memory
accessed.
@geky-bot
Copy link
Collaborator

Tests passed ✓, Code: 17112 B (+0.0%), Stack: 1448 B (+0.0%), Structs: 812 B (+0.0%)
Code Stack Structs Coverage
Default 17112 B (+0.0%) 1448 B (+0.0%) 812 B (+0.0%) Lines 2431/2594 lines (-0.0%)
Readonly 6230 B (+0.1%) 448 B (+0.0%) 812 B (+0.0%) Branches 1277/1608 branches (-0.1%)
Threadsafe 17964 B (+0.0%) 1448 B (+0.0%) 820 B (+0.0%) Benchmarks
Multiversion 17184 B (+0.0%) 1448 B (+0.0%) 816 B (+0.0%) Readed 29369693876 B (+0.0%)
Migrate 18776 B (+0.0%) 1752 B (+0.0%) 816 B (+0.0%) Proged 1482874766 B (+0.0%)
Error-asserts 17888 B (+0.0%) 1440 B (+0.0%) 812 B (+0.0%) Erased 1568888832 B (+0.0%)

lfs.c Outdated
Comment on lines 413 to 422
if (a->tag != 0) {
return false;
}
if (a->pair[0] != 0) {
return false;
}
if (a->pair[1] != 0) {
return false;
}
return true;

Choose a reason for hiding this comment

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

Nit: this could potentially be condensed (if not simplified) to:

    return ((a->tag == 0) && (a->pair[0] == 0) && (a->pair[1] == 0));

@geky
Copy link
Member

geky commented Mar 18, 2025

Hi @elupus, thanks for this. Looks good to me.

This wouldn't have been a blocker, but it's interesting to note this has zero impact on code size. I guess these loops were already unrolled given how small they are.

@geky-bot
Copy link
Collaborator

Tests passed ✓, Code: 17108 B (+0.0%), Stack: 1448 B (+0.0%), Structs: 812 B (+0.0%)
Code Stack Structs Coverage
Default 17108 B (+0.0%) 1448 B (+0.0%) 812 B (+0.0%) Lines 2431/2593 lines (+0.1%)
Readonly 6230 B (+0.1%) 448 B (+0.0%) 812 B (+0.0%) Branches 1277/1608 branches (-0.1%)
Threadsafe 17960 B (+0.0%) 1448 B (+0.0%) 820 B (+0.0%) Benchmarks
Multiversion 17180 B (+0.0%) 1448 B (+0.0%) 816 B (+0.0%) Readed 29369693876 B (+0.0%)
Migrate 18772 B (+0.0%) 1752 B (+0.0%) 816 B (+0.0%) Proged 1482874766 B (+0.0%)
Error-asserts 17888 B (+0.0%) 1440 B (+0.0%) 812 B (+0.0%) Erased 1568888832 B (+0.0%)

@geky geky changed the base branch from master to devel March 20, 2025 06:22
@geky geky merged commit 8ed63b2 into littlefs-project:devel Mar 20, 2025
93 checks passed
@elupus elupus deleted the fix/packing branch March 20, 2025 06:27
@elupus
Copy link
Contributor Author

elupus commented Mar 20, 2025

Thanx!

@geky
Copy link
Member

geky commented Mar 20, 2025

It's not quite in master yet, but will be shortly if this CI job succeeds. Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants