diff mbox series

[6/6] migration: fix uninitialized variable warning in migrate_send_rp_req_pages()

Message ID 20201103015228.2250547-7-kuhn.chenqun@huawei.com
State Accepted
Commit a24292830b7a356f528760e065c0012ff56e18ab
Headers show
Series fix uninitialized variable warning | expand

Commit Message

Chenqun (kuhn) Nov. 3, 2020, 1:52 a.m. UTC
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:
migration/migration.c: In function ‘migrate_send_rp_req_pages’:
migration/migration.c:384:8: warning: ‘received’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 384 |     if (received) {
     |        ^

Add a default value for 'received' to prevented the warning.

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
---
Cc: Juan Quintela <quintela@redhat.com>
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
---
 migration/migration.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Philippe Mathieu-Daudé Nov. 3, 2020, 2:22 a.m. UTC | #1
On 11/3/20 2:52 AM, Chen Qun wrote:
> 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:

> migration/migration.c: In function ‘migrate_send_rp_req_pages’:

> migration/migration.c:384:8: warning: ‘received’ may be used uninitialized in this function [-Wmaybe-uninitialized]

>  384 |     if (received) {

>      |        ^

> 

> Add a default value for 'received' to prevented the warning.

> 

> Reported-by: Euler Robot <euler.robot@huawei.com>

> Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>

> ---

> Cc: Juan Quintela <quintela@redhat.com>

> Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

> ---

>  migration/migration.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

> 

> diff --git a/migration/migration.c b/migration/migration.c

> index 9bb4fee5ac..de90486a61 100644

> --- a/migration/migration.c

> +++ b/migration/migration.c

> @@ -361,7 +361,7 @@ int migrate_send_rp_req_pages(MigrationIncomingState *mis,

>                                RAMBlock *rb, ram_addr_t start, uint64_t haddr)

>  {

>      void *aligned = (void *)(uintptr_t)(haddr & (-qemu_ram_pagesize(rb)));

> -    bool received;

> +    bool received = false;

>  

>      WITH_QEMU_LOCK_GUARD(&mis->page_request_mutex) {

>          received = ramblock_recv_bitmap_test_byte_offset(rb, start);

> 


Since this helps static analyzer:
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
diff mbox series

Patch

diff --git a/migration/migration.c b/migration/migration.c
index 9bb4fee5ac..de90486a61 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -361,7 +361,7 @@  int migrate_send_rp_req_pages(MigrationIncomingState *mis,
                               RAMBlock *rb, ram_addr_t start, uint64_t haddr)
 {
     void *aligned = (void *)(uintptr_t)(haddr & (-qemu_ram_pagesize(rb)));
-    bool received;
+    bool received = false;
 
     WITH_QEMU_LOCK_GUARD(&mis->page_request_mutex) {
         received = ramblock_recv_bitmap_test_byte_offset(rb, start);