[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/6] util/qemu-timer: fix uninitialized variable warning for expi
From: |
Chen Qun |
Subject: |
[PATCH 4/6] util/qemu-timer: fix uninitialized variable warning for expire_time |
Date: |
Tue, 3 Nov 2020 09:52:26 +0800 |
After the WITH_QEMU_LOCK_GUARD macro is added, the compiler cannot identify
that the statements in the macro must be executed. As a result, some variables
assignment statements in the macro may be considered as unexecuted by the
compiler.
The compiler showed warning:
util/qemu-timer.c: In function ‘timerlist_expired’:
util/qemu-timer.c:199:24: warning: ‘expire_time’ may be used uninitialized in
this function [-Wmaybe-uninitialized]
199 | return expire_time <= qemu_clock_get_ns(timer_list->clock->type);
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
util/qemu-timer.c: In function ‘timerlist_deadline_ns’:
util/qemu-timer.c:237:11: warning: ‘expire_time’ may be used uninitialized in
this function [-Wmaybe-uninitialized]
237 | delta = expire_time - qemu_clock_get_ns(timer_list->clock->type);
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Add a default value for 'expire_time' to prevented the warning.
Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
---
Cc: Paolo Bonzini <pbonzini@redhat.com>
---
util/qemu-timer.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/util/qemu-timer.c b/util/qemu-timer.c
index 8b73882fbb..3910003e86 100644
--- a/util/qemu-timer.c
+++ b/util/qemu-timer.c
@@ -183,7 +183,7 @@ bool qemu_clock_has_timers(QEMUClockType type)
bool timerlist_expired(QEMUTimerList *timer_list)
{
- int64_t expire_time;
+ int64_t expire_time = -1;
if (!qatomic_read(&timer_list->active_timers)) {
return false;
@@ -213,7 +213,7 @@ bool qemu_clock_expired(QEMUClockType type)
int64_t timerlist_deadline_ns(QEMUTimerList *timer_list)
{
int64_t delta;
- int64_t expire_time;
+ int64_t expire_time = -1;
if (!qatomic_read(&timer_list->active_timers)) {
return -1;
--
2.27.0
- [PATCH 0/6] fix uninitialized variable warning, Chen Qun, 2020/11/02
- [PATCH 2/6] hw/rdma/rdma_backend: fix uninitialized variable warning in rdma_poll_cq(), Chen Qun, 2020/11/02
- [PATCH 5/6] plugins/loader: fix uninitialized variable warning in plugin_reset_uninstall(), Chen Qun, 2020/11/02
- [PATCH 3/6] util/qemu-timer: fix uninitialized variable warning in timer_mod_anticipate_ns(), Chen Qun, 2020/11/02
- [PATCH 4/6] util/qemu-timer: fix uninitialized variable warning for expire_time,
Chen Qun <=
- [PATCH 1/6] target/xtensa: fix uninitialized variable warning, Chen Qun, 2020/11/02
- [PATCH 6/6] migration: fix uninitialized variable warning in migrate_send_rp_req_pages(), Chen Qun, 2020/11/02
- Re: [PATCH 0/6] fix uninitialized variable warning, Peter Maydell, 2020/11/03