summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Elliott Hughes <enh@google.com> 2020-05-19 10:29:03 -0700
committer Elliott Hughes <enh@google.com> 2020-05-19 10:29:03 -0700
commit67484eb5d5fbbd1b9a11b9f3a9fc17d870e83512 (patch)
tree4f22b186fa50ee6c4564dec4547fa1f21efbac3a
parent88536883e26cea512c95da0e6391d0f82403ea45 (diff)
AlarmManagerService.setKernelTime: fix incorrect limit.
There is no TIME_T_MAX, so someone wrote INT_MAX instead. Use std::numeric_limits<time_t>::max() so we can get the right answer on both 32-bit and 64-bit systems. Bug: http://b/156317457 Test: treehugger Change-Id: I19fdee8601f8b59c4ee0959d59be946bfab6e4d0
-rw-r--r--services/core/jni/com_android_server_AlarmManagerService.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/services/core/jni/com_android_server_AlarmManagerService.cpp b/services/core/jni/com_android_server_AlarmManagerService.cpp
index e79612fbf3d3..a99c0a3fa23e 100644
--- a/services/core/jni/com_android_server_AlarmManagerService.cpp
+++ b/services/core/jni/com_android_server_AlarmManagerService.cpp
@@ -40,6 +40,7 @@
#include <linux/rtc.h>
#include <array>
+#include <limits>
#include <memory>
namespace android {
@@ -213,22 +214,20 @@ int AlarmImpl::waitForAlarm()
static jint android_server_AlarmManagerService_setKernelTime(JNIEnv*, jobject, jlong nativeData, jlong millis)
{
AlarmImpl *impl = reinterpret_cast<AlarmImpl *>(nativeData);
- struct timeval tv;
- int ret;
- if (millis <= 0 || millis / 1000LL >= INT_MAX) {
+ if (millis <= 0 || millis / 1000LL >= std::numeric_limits<time_t>::max()) {
return -1;
}
- tv.tv_sec = (time_t) (millis / 1000LL);
- tv.tv_usec = (suseconds_t) ((millis % 1000LL) * 1000LL);
-
- ALOGD("Setting time of day to sec=%d\n", (int) tv.tv_sec);
+ struct timeval tv;
+ tv.tv_sec = (millis / 1000LL);
+ tv.tv_usec = ((millis % 1000LL) * 1000LL);
- ret = impl->setTime(&tv);
+ ALOGD("Setting time of day to sec=%ld", tv.tv_sec);
- if(ret < 0) {
- ALOGW("Unable to set rtc to %ld: %s\n", tv.tv_sec, strerror(errno));
+ int ret = impl->setTime(&tv);
+ if (ret < 0) {
+ ALOGW("Unable to set rtc to %ld: %s", tv.tv_sec, strerror(errno));
ret = -1;
}
return ret;