value_util.cc: Fix MaxValue() to no longer use designated initialization.#9851
Merged
value_util.cc: Fix MaxValue() to no longer use designated initialization.#9851
Conversation
dconeybe
added a commit
to firebase/firebase-cpp-sdk
that referenced
this pull request
May 27, 2022
…, which fixes a problematic usage of designated initialization
Collaborator
Coverage Report 1Affected Products
Test Logs |
wu-hui
approved these changes
May 27, 2022
Collaborator
Size Report 1Affected ProductsTest Logs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
In #9750, the implementation of
MaxValue()invalue_util.ccwas changed to avoid heap memory allocation that leaked memory. The fix created global variables so that the memory had static storage duration. However, these global variables used a C++20 feature called designated initialization, and this code base only supports C++11.I originally tried to change the designated initialization to aggregate initialization; however, one of the global variables had a "union" member variable that cannot be initialized with aggregate initialization because "when a union is initialized by aggregate initialization, only its first non-static data member is initialized" and the member to be initialized was not the first member.
So I just changed the implementation of MaxValue() to basically what it was before #9750, except that the object that was being allocated on the heap via a call to
calloc()is now allocated in static storage. This should make ASAN happy while also fixing the invalid usage of designated initialization.This bug was detected by a downstream build that was more strict and failed due to the use of a C++20 feature in a C++11 code base: firebase/firebase-cpp-sdk#967 (comment)
#no-changelog