Fix overflow/underflow problem in comparison

Here's overflow/underflow problem in comparators.
"when1 - when2" may suffer in overflow/underflow condition.
Comparing them directly can avoid this problem.

Change-Id: Id46af3db2adac90654210182d26ade1986ee0661
This commit is contained in:
Charles Tsai
2015-05-20 18:16:48 +08:00
parent bf17375e5e
commit cdaaeeec0d

View File

@@ -369,10 +369,10 @@ class AlarmManagerService extends SystemService {
public int compare(Batch b1, Batch b2) {
long when1 = b1.start;
long when2 = b2.start;
if (when1 - when2 > 0) {
if (when1 > when2) {
return 1;
}
if (when1 - when2 < 0) {
if (when1 < when2) {
return -1;
}
return 0;
@@ -1482,10 +1482,10 @@ class AlarmManagerService extends SystemService {
public int compare(Alarm a1, Alarm a2) {
long when1 = a1.whenElapsed;
long when2 = a2.whenElapsed;
if (when1 - when2 > 0) {
if (when1 > when2) {
return 1;
}
if (when1 - when2 < 0) {
if (when1 < when2) {
return -1;
}
return 0;