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 Uninitialized Variable Errors in GoogleTest's gtest-death-test.cc #2367

Closed
wants to merge 1 commit into from

Conversation

bgorlick
Copy link

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.

@digit-google
Copy link
Contributor

Please do not add files that belong to CMake-generated directories, this is not the way to solve the issue. See PR #2360 for a better way to solve the issue. Another one is simply to use GTest 1.11 or above with -DGTEST_ROOT=<path> to point to its installation path.

@jhasse jhasse closed this Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants