Fix integer overflow in libgui_test Surface_test
Integer overflow now causes abort (aosp/589659, aosp/589605), causing libgui_test to
fail one of the compositor tests.
Bug: 72229624
Test: adb shell /data/nativetest/libgui_test/libgui_test \
--gtest_filter=GetFrameTimestampsTest.CompositorTimingUpdatesBasic
Change-Id: I91c77ba53e5ed74034884c8e144e3c3198458aa5
diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp
index cd29d4a..8060b6e 100644
--- a/libs/gui/tests/Surface_test.cpp
+++ b/libs/gui/tests/Surface_test.cpp
@@ -22,6 +22,7 @@
#include <binder/ProcessState.h>
#include <configstore/Utils.h>
#include <cutils/properties.h>
+#include <inttypes.h>
#include <gui/BufferItemConsumer.h>
#include <gui/IDisplayEventConnection.h>
#include <gui/IProducerListener.h>
@@ -869,7 +870,7 @@
(iOldFrame == NO_FRAME_INDEX) ? nullptr : &mFrames[iOldFrame];
FrameEvents* newFrame = &mFrames[iNewFrame];
- uint64_t nOldFrame = iOldFrame + 1;
+ uint64_t nOldFrame = (iOldFrame == NO_FRAME_INDEX) ? 0 : iOldFrame + 1;
uint64_t nNewFrame = iNewFrame + 1;
// Latch, Composite, and Release the frames in a plausible order.