Skip to content

Commit 0426070

Browse files
authored
Fix ODR violation of FirestoreInternal in integration_test_util.cc (#559)
In the `TestFriend::CreateTestFirestoreInternal()` method defined in [integration_test_util.cc](https://github.com/firebase/firebase-cpp-sdk/blob/edad366983e6f4e7d8a1c3823d95c48c791a8853/firestore/integration_test_internal/src/util/integration_test_util.cc#L25) the expression `sizeof(FirestoreInternal)` is `116`. In contrast, in [firestore_android.cc](https://github.com/firebase/firebase-cpp-sdk/blob/edad366983e6f4e7d8a1c3823d95c48c791a8853/firestore/src/android/firestore_android.cc#L243) the expression `sizeof(FirestoreInternal)` is `128`. Before `bundle_listeners_mutex_` and `bundle_listeners_` were added to `FirestoreInternal` in #394 the expression `sizeof(FirestoreInternal)` was `112`. So we were basically getting lucky that the ODR caused *more* memory to be allocated by the call to `new FirestoreInternal(app)` than was needed; however, now that those two members were added to `FirestoreInternal` the `new FirestoreInternal(app)` call is allocating *fewer* bytes than needed, causing the initialization of `FirestoreInternal` to run off the end of its allocated memory. The fix is to include the Android-specific header when building for Android, and the "common" header on non-Android. Googlers can see b/192351260#comment13 for details.
1 parent 9b1bd93 commit 0426070

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

firestore/integration_test_internal/src/util/integration_test_util.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
#include "firebase/app.h"
1010
#include "firebase/firestore.h"
1111
#include "firestore/src/common/hard_assert_common.h"
12+
13+
#if !defined(__ANDROID__)
1214
#include "firestore/src/main/firestore_main.h"
15+
#else
16+
#include "firestore/src/android/firestore_android.h"
17+
#endif // !defined(__ANDROID__)
1318

1419
namespace firebase {
1520
namespace firestore {

0 commit comments

Comments
 (0)