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

refactor: fix unread variable warnings #4405

Merged
merged 2 commits into from
Mar 1, 2024

Conversation

jmayclin
Copy link
Contributor

@jmayclin jmayclin commented Feb 6, 2024

Description of changes:

Cppcheck is failing in #4404 because zero initializing variables is causing new unreadVariable warnings to surface. Rather than adding new suppressions, this PR fixes those warnings by pushing the variable declaration down a scope.

This is being done in a separate PR to keep #4404 as an entirely automated PR.

Call-outs:

Note that under any reasonable optimization level this code is expected to be identical. This was spot checked with GodBolt: https://godbolt.org/z/vaYeWecfM.

Testing:

I first gathered all of the unreadVariable warnings from cppcheck. After fixing those, I first reapplied the clang-tidy fixes

run-clang-tidy . -p build/ -use-color -quiet -checks=cppcoreguidelines-init-variables -fix

I then ran cppcheck

cppcheck --enable=style \
    --project=build/compile_commands.json \
    --output-file=report.txt \
    -j $(nproc)

I finally verified that there were 0 unreadVariable warnings in the new report.

[ec2-user]$ cat report.txt | grep unreadVariable | wc -l
0

Current CI and tests should be sufficient to ensure that there was no behavior change.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added the s2n-core team label Feb 6, 2024
@jmayclin jmayclin marked this pull request as ready for review February 6, 2024 03:14
@jmayclin jmayclin enabled auto-merge (squash) February 28, 2024 19:03
@jmayclin jmayclin merged commit 74e66fd into aws:main Mar 1, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants