end2end: Fix UB in refresh event time computations [10/N]
The function to compute the next event time could overflow near INT64_MIN and INT64_MAX, and as the values were signed, the result was undefined behavior, leading to errors that were caught later. This was problematic as other part of the generator assumes INT64_MIN (via std::chrono::steady_clock::time_point::min()) is a reasonable choice for an initial "last emitted event time" when first starting up. To fix this, the function was re-implemented to use uint64_t internally, and adjusted to avoid underflow completely, and overflow as much as possible. Overflow is still however possible when the next event time is greater than time_point::max(), and this is now caught with a CHECK(), which aborts the process. In normal use, this could only be a problem 317 years after the last boot, as that is when the clock count starts on Linux. Because of that, it should not cause a problem in usage in tests, and probably would not even be an issue in production. The internal tests now covers values at the extreme values where possible to ensure those values work. Flag: TEST_ONLY Bug: 372735083 Test: atest surfaceflinger_end2end_tests Change-Id: I6db126cbeeb2dc58e9a379f53925d1d9f250102b
Loading
Please register or sign in to comment