Remove some dead assignments from clang analyzer report
cover Remove some dead assignments from clang analyzer report
Running the static checker clang-analyzer on the qemu sources, I found a few dead assignments.
This patchset removes a few of those.
Amit Shah (6):
vl.c: Remove dead assignment
virtio: net: remove dead assignment
x86: translate.c: remove dead assignment
hw/vga.c: remove dead assignment
qcow2-refcount: remove dead assignment
json-parser: remove dead increment
block/qcow2-refcount.c | 1 - hw/vga.c | 1 - hw/virtio-net.c | 2 +- json-parser.c | 2 -- target-i386/translate.c | 2 -- vl.c | 6 +----- 6 files changed, 2 insertions(+), 12 deletions(-)
PATCH 1/6 vl.c: Remove dead assignment
clang-analyzer pointed out the value of 'sockets' is never reused.
--- vl.c | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-)
vl.c +1 -5
@@ -2613,17 +2613,13 @@ static void smp_parse(const char *optarg) threads = threads >0 ? threads :1 ;if (smp ==0 ) { smp = cores * threads * sockets; - }else { - sockets = smp / (cores * threads); } }else {if (cores ==0 ) { threads = threads >0 ? threads :1 ; cores = smp / (sockets * threads); }else { -if (sockets ==0 ) { - sockets = smp / (cores * threads); - }else { +if (sockets) { threads = smp / (cores * sockets); } }
Signature · 1 line
1.6.2.5
PATCH 2/6 virtio: net: remove dead assignment
clang-analyzer points out value assigned to 'len' is not used.
--- hw/virtio-net.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/virtio-net.c +1 -1
@@ -532,7 +532,7 @@ static ssize_t virtio_net_receive(VLANClientState *nc, const uint8_t *buf, size_int len, total;struct iovec sg[VIRTQUEUE_MAX_SIZE ]; - len = total =0 ; + total =0 ;if ((i !=0 && !n->mergeable_rx_bufs) ||virtqueue_pop (n->rx_vq, &elem) ==0 ) {
Signature · 1 line
1.6.2.5
PATCH 3/6 x86: translate.c: remove dead assignment
clang-analyzer points out a redundant assignment.
--- target-i386/translate.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
target-i386/translate.c +0 -2
@@ -2207,8 +2207,6 @@ static void gen_add_A0_ds_seg(DisasContext *s)if (s->override >=0 ) { override = s->override; must_add_seg =1 ; - }else { - override =R_DS ; }if (must_add_seg) {#ifdef TARGET_X86_64
Signature · 1 line
1.6.2.5
PATCH 4/6 hw/vga.c: remove dead assignment
clang-analyzer points out a redundant assignment.
--- hw/vga.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
hw/vga.c +0 -1
@@ -1303,7 +1303,6 @@ static void vga_draw_text(VGACommonState *s, int full_update) line_offset = s->line_offset;vga_get_text_resolution (s, &width, &height, &cw, &cheight); - x_incr = cw * ((ds_get_bits_per_pixel (s->ds) +7 ) >>3 );if ((height * width) >CH_ATTR_SIZE ) {/* better than nothing: exit if transient size is too big */ return ;
Signature · 1 line
1.6.2.5
PATCH 5/6 qcow2-refcount: remove dead assignment
clang-analyzer points out a redundant assignment.
--- block/qcow2-refcount.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
block/qcow2-refcount.c +0 -1
@@ -511,7 +511,6 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, l2_table =NULL ; l1_table =NULL ; l1_size2 = l1_size *sizeof (uint64_t ); - l1_allocated =0 ;if (l1_table_offset != s->l1_table_offset) {if (l1_size2 !=0 ) { l1_table =qemu_mallocz (align_offset (l1_size2,512 ));
Signature · 1 line
1.6.2.5
PATCH 6/6 json-parser: remove dead increment
clang-analyzer points out a redundant increment.
--- json-parser.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
json-parser.c +0 -2
@@ -247,8 +247,6 @@ static QString *qstring_from_escaped_str(JSONParserContext *ctxt, QObject *token } } - ptr++; -return str; out:
Signature · 1 line
1.6.2.5
[Qemu-devel] Re: [PATCH 5/6] qcow2-refcount: remove dead assignment
In reply to Amit ShahQuoted 12 lines · Amit Shah
clang-analyzer points out a redundant assignment.
Signed-off-by Amit Shah<[email protected]>--- block/qcow2-refcount.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)block/qcow2-refcount.c +0
-0
block/qcow2-refcount.c int qcow2_update_snapshot_refcount(BlockDriverState *bs, · line 516
Quoted 7 lines
block/qcow2-refcount.c +0
-1@@ -511,7 +511,6 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, l2_table =NULL ; l1_table =NULL ; l1_size2 = l1_size *sizeof (uint64_t ); - l1_allocated =0 ;if (l1_table_offset != s->l1_table_offset) {if (l1_size2 !=0 ) { l1_table =qemu_mallocz (align_offset (l1_size2,512 ));
I'd remove the l1_allocated = 0 assignment in the else branch instead (the idea is, assign l1_allocated = 1 right after any qemu_malloc.
Paolo
[Qemu-devel] Re: [PATCH 5/6] qcow2-refcount: remove dead assignment
Quoted 8 lines · Paolo Bonzini
Quoted 7 lines · Amit Shah
clang-analyzer points out a redundant assignment.
Signed-off-by Amit Shah<[email protected]>--- block/qcow2-refcount.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
Quoted 15 lines
block/qcow2-refcount.c int qcow2_update_snapshot_refcount(BlockDriverState *bs, · line 516
Quoted 12 lines
block/qcow2-refcount.c +0
-1@@ -511,7 +511,6 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, l2_table =NULL ; l1_table =NULL ; l1_size2 = l1_size *sizeof (uint64_t ); - l1_allocated =0 ;if (l1_table_offset != s->l1_table_offset) {if (l1_size2 !=0 ) { l1_table =qemu_mallocz (align_offset (l1_size2,512 ));I'd remove the
l1_allocated= 0 assignment in the else branch instead (the idea is, assignl1_allocated= 1 right after anyqemu_malloc.
I thought about that too, but since the else{} part has some other code, I decided to go that way.
(Also that if such assignments aren't placed in common code, they'll be pointed out when someone tries to use them with the default undefined value.)
Amit
[Qemu-devel] Re: [PATCH 2/6] virtio: net: remove dead assignment
In reply to Amit ShahQuoted 3 lines · Amit Shah
clang-analyzer points out value assigned to 'len' is not used.
Signed-off-by Amit Shah <[email protected]>
Quoted 21 lines
--- hw/virtio-net.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)hw/virtio-net.c +1
-1@@ -532,7 +532,7 @@ static ssize_t virtio_net_receive(VLANClientState *nc, const uint8_t *buf, size_int len, total;struct iovec sg[VIRTQUEUE_MAX_SIZE ]; - len = total =0 ; + total =0 ;if ((i !=0 && !n->mergeable_rx_bufs) ||virtqueue_pop (n->rx_vq, &elem) ==0 ) {Signature · 1 line
1.6.2.5
Anthony Liguori
AppliedRe: [Qemu-devel] [PATCH 1/6] vl.c: Remove dead assignment
In reply to Amit ShahQuoted 5 lines · Amit Shah
clang-analyzer pointed out the value of 'sockets' is never reused.
Signed-off-by Amit Shah<[email protected]>CC Andre Przywara<[email protected]>
Applied. Thanks.
Regards,
Anthony Liguori
Quoted 28 lines
--- vl.c | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-)vl.c +1
-5@@ -2613,17 +2613,13 @@ static void smp_parse(const char *optarg) threads = threads>0 ? threads :1 ;if (smp ==0 ) { smp = cores * threads * sockets; - }else { - sockets = smp / (cores * threads); } }else {if (cores ==0 ) { threads = threads>0 ? threads :1 ; cores = smp / (sockets * threads); }else { -if (sockets ==0 ) { - sockets = smp / (cores * threads); - }else { +if (sockets) { threads = smp / (cores * sockets); } }