Skip to content

value_util.cc: Fix MaxValue() to no longer use designated initialization. #9851

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

Merged
merged 3 commits into from
May 27, 2022

Conversation

dconeybe
Copy link
Contributor

In #9750, the implementation of MaxValue() in value_util.cc was 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

@dconeybe dconeybe self-assigned this May 27, 2022
@dconeybe dconeybe changed the base branch from master to dconeybe/PythonHostExecutableFix May 27, 2022 03:56
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
@google-oss-bot
Copy link

google-oss-bot commented May 27, 2022

Coverage Report 1

Affected Products

  • FirebaseFirestore-iOS-FirebaseFirestore.framework

    Overall coverage changed from 88.38% (68bc0b5) to 88.42% (0ec99c5) by +0.05%.

    FilenameBase (68bc0b5)Merge (0ec99c5)Diff
    document.nanopb.cc96.52%98.26%+1.74%
    leveldb_key.cc98.14%98.63%+0.49%
    ordered_code.cc93.90%94.39%+0.49%
    value_util.cc95.59%95.67%+0.09%

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/Xb8DQU48yd.html

Base automatically changed from dconeybe/PythonHostExecutableFix to master May 27, 2022 14:13
@dconeybe dconeybe marked this pull request as ready for review May 27, 2022 14:24
@dconeybe dconeybe requested a review from wu-hui May 27, 2022 14:24
@dconeybe dconeybe assigned wu-hui and unassigned dconeybe May 27, 2022
@wu-hui wu-hui assigned dconeybe and unassigned wu-hui May 27, 2022
@google-oss-bot
Copy link

@dconeybe dconeybe merged commit 887a72a into master May 27, 2022
@dconeybe dconeybe deleted the dconeybe/DesignatedInitializersFix branch May 27, 2022 17:01
@firebase firebase locked and limited conversation to collaborators Jun 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants