Skip to content

Commit 6d03dfd

Browse files
authored
Fix the build on Windows (#3332)
1 parent 6439e65 commit 6d03dfd

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

Firestore/core/src/firebase/firestore/nanopb/writer.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@ ByteStringWriter::~ByteStringWriter() {
6262
void ByteStringWriter::Append(const void* data, size_t size) {
6363
if (size == 0) return;
6464

65+
pb_size_t pb_size = CheckedSize(size);
6566
size_t current_size = this->size();
66-
size_t min_capacity = current_size + size;
67+
size_t min_capacity = current_size + pb_size;
6768
HARD_ASSERT(min_capacity >= current_size); // Avoid overflow
6869

6970
Reserve(min_capacity);
7071
uint8_t* pos = this->pos();
7172
std::memcpy(pos, data, size);
72-
buffer_->size += size;
73+
buffer_->size += pb_size;
7374
}
7475

7576
void ByteStringWriter::Reserve(size_t min_capacity) {

Firestore/core/src/firebase/firestore/timestamp.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace firebase {
3131

3232
namespace {
3333

34-
constexpr int32_t kNanosPerSecond = 1E9;
34+
constexpr int32_t kNanosPerSecond = 1000 * 1000 * 1000;
3535

3636
/**
3737
* Creates a `Timestamp` from the given non-normalized inputs.

Firestore/core/test/firebase/firestore/model/field_value_test.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,13 @@ static time_point kDate2 = testutil::MakeTimePoint(2016, 10, 21, 15, 32, 0);
218218
static Timestamp kTimestamp2{1477063920, 0};
219219

220220
TEST(FieldValueTest, Equality) {
221+
// Avoid statically dividing by zero; MSVC considers this an error.
222+
double zero = 0.0;
221223
testutil::EqualsTester<FieldValue>()
222224
.AddEqualityGroup(FieldValue::Null(), Value(nullptr))
223225
.AddEqualityGroup(FieldValue::False(), Value(false))
224226
.AddEqualityGroup(FieldValue::True(), Value(true))
225-
.AddEqualityGroup(Value(0.0 / 0.0), Value(ToDouble(kCanonicalNanBits)),
227+
.AddEqualityGroup(Value(0.0 / zero), Value(ToDouble(kCanonicalNanBits)),
226228
Value(ToDouble(kAlternateNanBits)),
227229
Value(std::nan("1")), Value(std::nan("2")))
228230
// -0.0 and 0.0 compareTo the same but are not equal.

Firestore/core/test/firebase/firestore/timestamp_test.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ using Ms = std::chrono::milliseconds;
3939

4040
const auto kUpperBound = 253402300800L - 1;
4141
const auto kLowerBound = -62135596800L;
42+
constexpr int32_t kNanosPerSecond = 1000 * 1000 * 1000;
4243

4344
// For near-bounds tests that use <chrono>, it's important to only run them if
4445
// system_clock::duration can represent values this large (e.g., on Linux, it's
@@ -91,7 +92,7 @@ TEST(Timestamp, Now) {
9192
int64_t seconds_diff = spec.tv_sec - now.seconds();
9293
int64_t nanos_diff = spec.tv_nsec - now.nanoseconds();
9394

94-
nanos_diff = std::abs(seconds_diff * 1E9 + nanos_diff);
95+
nanos_diff = std::abs(seconds_diff * kNanosPerSecond + nanos_diff);
9596

9697
// Assert that time produced by Timestamp and Abseil are within 10ms of each
9798
// other. In practice these are only a few microseconds apart, but the

0 commit comments

Comments
 (0)