Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/src/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@ inline timespec MsToTimespec(int milliseconds) {
inline timespec MsToAbsoluteTimespec(int milliseconds) {
timespec t;
clock_gettime(CLOCK_REALTIME, &t);
t.tv_nsec += milliseconds * internal::kNanosecondsPerMillisecond;
NormalizeTimespec(&t);

const int64_t nanoseconds =
t.tv_nsec + (t.tv_sec * internal::kNanosecondsPerSecond) +
(milliseconds * internal::kNanosecondsPerMillisecond);

t.tv_sec = nanoseconds / internal::kNanosecondsPerSecond;
t.tv_nsec = nanoseconds % internal::kNanosecondsPerSecond;
return t;
}

Expand Down
8 changes: 8 additions & 0 deletions app/tests/time_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ TEST(TimeTests, ComparisonTests) {
EXPECT_EQ(firebase::internal::TimespecCmp(t1, t1), 0);
EXPECT_EQ(firebase::internal::TimespecCmp(t2, t2), 0);
}

TEST(TimeTests, MsToAbsoluteTimespecTest) {
const timespec t1 = firebase::internal::MsToAbsoluteTimespec(0);
const timespec t2 = firebase::internal::MsToAbsoluteTimespec(10000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these value test for previous overflow scenarios?

If so a comment saying that this tests for overlfow on 32 bit systems would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as the test gets run on a 32-bit architecture it will detect the overflow. I'm not sure how our GitHub Actions are set up and if they trigger these tests on 32-bit platforms. I've opened a temporary PR #1043 to see if any of the GitHub Actions fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also added this inline comment to time_test.cc:

This test verifies the fix for the old integer overflow bug on 32-bit architectures: #1042.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've verified the fix using GitHub Actions in #1043

const int64_t ms1 = firebase::internal::TimespecToMs(t1);
const int64_t ms2 = firebase::internal::TimespecToMs(t2);
ASSERT_NEAR(ms1, ms2 - 10000, 300);
}
#endif

// Test GetTimestamp function
Expand Down
4 changes: 4 additions & 0 deletions release_build_files/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,10 @@ code.
cause duplicate symbol linker errors in conjunction with other libraries
([#989](https://github.com/firebase/firebase-cpp-sdk/issues/989)).
- GMA (iOS): Updated iOS dependency to Google Mobile Ads SDK version 9.7.0.
- General (Android,iOS,Linux,macOS 32-bit): Fixed an integer overflow which
could result in a crash or premature return when waiting for a `Future`
with a timeout
([#1042](https://github.com/firebase/firebase-cpp-sdk/pull/1042)).

### 9.3.0
- Changes
Expand Down