Skip to content

Commit 7fcf771

Browse files
committed
fix(android): overflow due to incorrect data type for time
1 parent 4ca6d26 commit 7fcf771

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

android/measure/src/main/jni/anr_handler.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static bool init_signal_catcher_tid() {
118118
return true;
119119
}
120120

121-
static void notifyAnrDetected(long timeMs) {
121+
static void notifyAnrDetected(long long timeMs) {
122122
if (!is_anr_handler_enabled) {
123123
MSR_LOGD("ANR handler not enabled, discarding detected ANR");
124124
return;
@@ -155,20 +155,20 @@ static void notifyAnrDetected(long timeMs) {
155155
break;
156156
}
157157

158-
MSR_LOGD("ANR detected at %ld, notifying via JNI", timeMs);
158+
MSR_LOGD("ANR detected at %lld, notifying via JNI", timeMs);
159159
(*env)->CallVoidMethod(env, gBridgeObj, notifyAnrDetectedMethod, timeMs);
160160
if (check_and_clear_exc(env)) {
161161
MSR_LOGE("Failed to call notifyAnrDetected");
162162
}
163163
}
164164

165-
static long get_current_time_ms() {
165+
static long long get_current_time_ms() {
166166
struct timespec ts;
167167
if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
168168
MSR_LOGE("Failed to get current time");
169169
return -1;
170170
}
171-
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
171+
return (long long)ts.tv_sec * 1000LL;
172172
}
173173

174174
static void block_sigquit() {
@@ -195,7 +195,7 @@ static void *watchdog_start_routine(__unused void *_) {
195195
MSR_LOGE("Failed to wait on semaphore, ANR detection won't work");
196196
break;
197197
}
198-
long time = get_current_time_ms();
198+
long long time = get_current_time_ms();
199199
notifyAnrDetected(time);
200200
syscall(SYS_tgkill, process_id, signal_catcher_tid, SIGQUIT);
201201
unblock_sigquit();

0 commit comments

Comments
 (0)