diff options
author | Wei (GPS SD) Chen <quic_weic@quicinc.com> | 2021-12-17 14:23:02 -0800 |
---|---|---|
committer | Wei (GPS SD) Chen <quic_weic@quicinc.com> | 2022-01-05 13:25:22 -0800 |
commit | 273653338f676372d8ab47261e39f8ab62465694 (patch) | |
tree | 3f56fe537f19d447f17e1329d92a3f89b50ea320 | |
parent | 96d2b390a6efac3512cb670bf8539b3bc3936ceb (diff) |
Elapsed time: fix potential issue due to unsigned arithmetic
There is an issue that substraction of two unsigned number can
cause overflow/underflow. Force integer to signed 64 bit before
doing arithmetic operation
Change-Id: I94d6f398ee95e2e045e88da2820fc39a9efa3099
CRs-fixed: 3096831
-rw-r--r-- | core/LocApiBase.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/core/LocApiBase.cpp b/core/LocApiBase.cpp index 80d1e3f..9d92810 100644 --- a/core/LocApiBase.cpp +++ b/core/LocApiBase.cpp @@ -1098,16 +1098,20 @@ bool ElapsedRealtimeEstimator::getElapsedRealtimeForGpsTime( // We have valid association if (mTimePairMeasReport.gpsTime.gpsWeek != 0) { timePair = mTimePairMeasReport; - LOC_LOGv("user meas time association"); + LOC_LOGv("use meas time association"); } else if (mTimePairPVTReport.gpsTime.gpsWeek != 0) { - LOC_LOGv("user PVT time association"); + LOC_LOGv("use PVT time association"); timePair = mTimePairPVTReport; } else { return false; } - gpsTimeDiffMsec = (gpsTimeAtOrigin.gpsWeek - timePair.gpsTime.gpsWeek) * MSEC_IN_ONE_WEEK + - (gpsTimeAtOrigin.gpsTimeOfWeekMs - timePair.gpsTime.gpsTimeOfWeekMs); + int64_t originMsec = (int64_t)gpsTimeAtOrigin.gpsWeek * (int64_t)MSEC_IN_ONE_WEEK + + (int64_t)gpsTimeAtOrigin.gpsTimeOfWeekMs; + int64_t timePairMsec = (int64_t)timePair.gpsTime.gpsWeek * (int64_t)MSEC_IN_ONE_WEEK + + (int64_t)timePair.gpsTime.gpsTimeOfWeekMs; + gpsTimeDiffMsec = originMsec - timePairMsec; + qtimerNsecAtOrigin = timePair.qtimerTick * 10000/192 + gpsTimeDiffMsec * 1000000; clock_gettime(CLOCK_BOOTTIME, &curBootTime); |