* [PATCH] m48t59-test: remove shadowed variables and cleanup
@ 2023-09-25 14:47 Paolo Bonzini
2023-09-25 15:09 ` Thomas Huth
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2023-09-25 14:47 UTC (permalink / raw)
To: qemu-devel; +Cc: armbru
Rename the variable "s" and, while at it, avoid the chance of an overflow in the
computation of ABS(t - s).
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
tests/qtest/m48t59-test.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/tests/qtest/m48t59-test.c b/tests/qtest/m48t59-test.c
index 843d2ced8e2..6c0b3dd6463 100644
--- a/tests/qtest/m48t59-test.c
+++ b/tests/qtest/m48t59-test.c
@@ -192,19 +192,22 @@ static void bcd_check_time(void)
}
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;
- t = (long)mktime(datep);
- s = (long)mktime(&start);
- if (t < s) {
- g_test_message("RTC is %ld second(s) behind wall-clock", (s - t));
+ date_s = (long)mktime(datep);
+ start_s = (long)mktime(&start);
+ if (date_s < start_s) {
+ diff = start_s - date_s;
+ g_test_message("RTC is %ld second(s) behind wall-clock", diff);
} 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(s);
--
2.41.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] m48t59-test: remove shadowed variables and cleanup
2023-09-25 14:47 [PATCH] m48t59-test: remove shadowed variables and cleanup Paolo Bonzini
@ 2023-09-25 15:09 ` Thomas Huth
2023-09-26 12:45 ` Markus Armbruster
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Huth @ 2023-09-25 15:09 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: armbru
On 25/09/2023 16.47, Paolo Bonzini wrote:
> Rename the variable "s" and, while at it, avoid the chance of an overflow in the
> computation of ABS(t - s).
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> tests/qtest/m48t59-test.c | 17 ++++++++++-------
> 1 file changed, 10 insertions(+), 7 deletions(-)
I've got a patch for this in my pull request from today already:
https://lore.kernel.org/qemu-devel/20230925090100.45632-4-thuth@redhat.com
Thomas
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] m48t59-test: remove shadowed variables and cleanup
2023-09-25 15:09 ` Thomas Huth
@ 2023-09-26 12:45 ` Markus Armbruster
0 siblings, 0 replies; 3+ messages in thread
From: Markus Armbruster @ 2023-09-26 12:45 UTC (permalink / raw)
To: Thomas Huth; +Cc: Paolo Bonzini, qemu-devel
Thomas Huth <thuth@redhat.com> writes:
> On 25/09/2023 16.47, Paolo Bonzini wrote:
>> Rename the variable "s" and, while at it, avoid the chance of an overflow in the
>> computation of ABS(t - s).
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>> tests/qtest/m48t59-test.c | 17 ++++++++++-------
>> 1 file changed, 10 insertions(+), 7 deletions(-)
>
> I've got a patch for this in my pull request from today already:
>
> https://lore.kernel.org/qemu-devel/20230925090100.45632-4-thuth@redhat.com
Commit 926bef1d82bb9eb7a752aa128d9e70b808906243.
Paolo's patch still applies, and "avoid the chance of an overflow in the
computation of ABS(t - s)" makes me think we still want it. The commit
message needs a tweak, though, since the patch no longer removes
shadowed variables.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-26 12:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-25 14:47 [PATCH] m48t59-test: remove shadowed variables and cleanup Paolo Bonzini
2023-09-25 15:09 ` Thomas Huth
2023-09-26 12:45 ` Markus Armbruster
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.