mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 09:43:56 -06:00
m48t59-test: avoid possible overflow on ABS
Originally meant to avoid a shadowed variable "s", which was fixed by renaming the outer declaration to "qts". Avoid the chance of an overflow in the computation of ABS(t - s). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
973d3ea5a1
commit
168d46749d
1 changed files with 10 additions and 7 deletions
|
@ -192,19 +192,22 @@ static void bcd_check_time(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(tm_cmp(&start, datep) <= 0 && tm_cmp(datep, &end) <= 0)) {
|
if (!(tm_cmp(&start, datep) <= 0 && tm_cmp(datep, &end) <= 0)) {
|
||||||
long t, s;
|
long date_s, start_s;
|
||||||
|
unsigned long diff;
|
||||||
|
|
||||||
start.tm_isdst = datep->tm_isdst;
|
start.tm_isdst = datep->tm_isdst;
|
||||||
|
|
||||||
t = (long)mktime(datep);
|
date_s = (long)mktime(datep);
|
||||||
s = (long)mktime(&start);
|
start_s = (long)mktime(&start);
|
||||||
if (t < s) {
|
if (date_s < start_s) {
|
||||||
g_test_message("RTC is %ld second(s) behind wall-clock", (s - t));
|
diff = start_s - date_s;
|
||||||
|
g_test_message("RTC is %ld second(s) behind wall-clock", diff);
|
||||||
} else {
|
} else {
|
||||||
g_test_message("RTC is %ld second(s) ahead of wall-clock", (t - s));
|
diff = date_s - start_s;
|
||||||
|
g_test_message("RTC is %ld second(s) ahead of wall-clock", diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_assert_cmpint(ABS(t - s), <=, wiggle);
|
g_assert_cmpint(diff, <=, wiggle);
|
||||||
}
|
}
|
||||||
|
|
||||||
qtest_quit(qts);
|
qtest_quit(qts);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue