- 
                Notifications
    You must be signed in to change notification settings 
- Fork 931
fix: avoid assuming struct packing #1084
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
Conversation
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.
| Tests passed ✓, Code: 17112 B (+0.0%), Stack: 1448 B (+0.0%), Structs: 812 B (+0.0%)
 | 
        
          
                lfs.c
              
                Outdated
          
        
      | if (a->tag != 0) { | ||
| return false; | ||
| } | ||
| if (a->pair[0] != 0) { | ||
| return false; | ||
| } | ||
| if (a->pair[1] != 0) { | ||
| return false; | ||
| } | ||
| return true; | 
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.
Nit: this could potentially be condensed (if not simplified) to:
    return ((a->tag == 0) && (a->pair[0] == 0) && (a->pair[1] == 0));
| 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. | 
| Tests passed ✓, Code: 17108 B (+0.0%), Stack: 1448 B (+0.0%), Structs: 812 B (+0.0%)
 | 
| Thanx! | 
| It's not quite in master yet, but will be shortly if this CI job succeeds. Thanks for the PR! | 
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.