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

Fix unitialized variable in zstream redup command #10244

Merged
merged 1 commit into from
Apr 23, 2020

Conversation

behlendorf
Copy link
Contributor

@behlendorf behlendorf commented Apr 23, 2020

Motivation and Context

Issue #10241 .

Description

Fix uninitialized variable in zstream redup command. The compiler
may determine the 'stream_offset' variable can be uninitialized
because not all rdt_lookup() exit paths set it. This should never
happen in practice as documented by the assert, but initialize it
regardless to resolve the warning.

How Has This Been Tested?

Locally compiled.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (a change to man pages or other documentation)

Checklist:

  • My code follows the ZFS on Linux code style requirements.
  • I have updated the documentation accordingly.
  • I have read the contributing document.
  • I have added tests to cover my changes.
  • I have run the ZFS Test Suite with this change applied.
  • All commit messages are properly formatted and contain Signed-off-by.

Fix uninitialized variable in `zstream redup` command.  The compiler
may determine the 'stream_offset' variable can be uninitialized
because not all rdt_lookup() exit paths set it.  This should never
happen in practice as documented by the assert, but initialize it
regardless to resolve the warning.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue openzfs#10241
@behlendorf behlendorf added Type: Building Indicates an issue related to building binaries Status: Code Review Needed Ready for review and testing labels Apr 23, 2020
@behlendorf behlendorf requested a review from ahrens April 23, 2020 16:31
Copy link
Member

@ahrens ahrens left a comment

Choose a reason for hiding this comment

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

Sorry about that, thanks for fixing. Is this check part of the automated builds? If so, maybe we can turn these warnings into errors, so that we'll notice them when the PR is still open.

@behlendorf
Copy link
Contributor Author

I was wondering myself why the CI didn't catch it. We do convert all warnings to fatal errors when building in the CI. It looks like this might have been missed because none of the bot were running a new enough version of gcc. There seems to be no warning on older versions.

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Apr 23, 2020
@behlendorf behlendorf merged commit 6de3e59 into openzfs:master Apr 23, 2020
@behlendorf
Copy link
Contributor Author

Following up on why the CI missed this. It turns out the reason we didn't catch this is precisely because we mainly build with debugging enabled. When --enable-debug is specified gcc recognizes the path where stream_offset doesn't get initialized as fatal and thus it can't be uninitialized and there's no warning. Conversely, we do see the warning in production builds, but since it's a production build the warning isn't promoted to an error and the build completes successfully.

@Hi-Angel
Copy link

Following up on why the CI missed this. It turns out the reason we didn't catch this is precisely because we mainly build with debugging enabled. When --enable-debug is specified gcc recognizes the path where stream_offset doesn't get initialized as fatal and thus it can't be uninitialized and there's no warning. Conversely, we do see the warning in production builds, but since it's a production build the warning isn't promoted to an error and the build completes successfully.

That's a detailed analysis. I think it might be worth noting that the more optimizations enabled, the more likely compiler to produce various warnings. It is irrelevant to debug-codepaths vs release-codepaths stuff, like the one you stumbled upon here. Rather it's just how code analyzer works. IIRC it is the same for both Clang and GCC. I think it might be less visible with C code though (I've seen the most of such discrepancy with C++). Offhand I can't find reports on this in my browser history, but I can try to find examples if anybody wants.

That is just something to bear in mind, so not to spend time trying to figure out why release build produce a warning that is missing in debug one. Perhaps you may want to enable a -O3 buiding pass in CI, maybe even with -flto.

as-com pushed a commit to as-com/zfs that referenced this pull request Jun 20, 2020
Fix uninitialized variable in `zstream redup` command.  The compiler
may determine the 'stream_offset' variable can be uninitialized
because not all rdt_lookup() exit paths set it.  This should never
happen in practice as documented by the assert, but initialize it
regardless to resolve the warning.

Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes openzfs#10241
Closes openzfs#10244 
(cherry picked from commit 6de3e59)
jsai20 pushed a commit to jsai20/zfs that referenced this pull request Mar 30, 2021
Fix uninitialized variable in `zstream redup` command.  The compiler
may determine the 'stream_offset' variable can be uninitialized
because not all rdt_lookup() exit paths set it.  This should never
happen in practice as documented by the assert, but initialize it
regardless to resolve the warning.

Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes openzfs#10241
Closes openzfs#10244
@behlendorf behlendorf deleted the issue-10241 branch April 19, 2021 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested) Type: Building Indicates an issue related to building binaries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants