Fix Uninitialized Variable Errors in GoogleTest's gtest-death-test.cc #2367
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This pull request addresses compilation errors encountered in GoogleTest's gtest-death-test.cc due to potentially uninitialized usage of the dummy variable. These errors were preventing successful compilation of the ninja using GoogleTest.
Issues Addressed
The errors being thrown were as follows:
error: ‘dummy’ may be used uninitialized [-Werror=maybe-uninitialized]
This error was caused by the dummy variable in the StackGrowsDown() function potentially being used before it was initialized.
/ninja/build-cmake/_deps/googletest-src/googletest/src/gtest-death-test.cc:1305:24: error: ‘dummy’ may be used uninitialized [-Werror=maybe-uninitialized]
1305 | StackLowerThanAddress(&dummy, &result);
Changes Made
Initialized the dummy variable to zero within the StackGrowsDown() function to ensure it is never used uninitialized.
This change resolves the compilation errors and does not alter the intended functionality of the tests.
Impact
This fix ensures that ninja can be compiled successfully with GoogleTest, specifically addressing the issues with strict compiler settings regarding uninitialized variables. It enhances the stability and reliability of the build process.
Testing
After making these changes, I successfully compiled ninja with GoogleTest without encountering the previous errors.
All tests related to the modified functionality have been executed to ensure they pass and behave as expected.
Additional Notes
This fix is critical for environments where compiler settings treat warnings as errors, which is common in various CI/CD pipelines and strict development setups.