Skip to contentSkip to conversation

Remove some dead assignments from clang analyzer report

PATCH Applied Amit Shah 4 participants 11 messages Jan 13, 2010 Block layer

lore
Share & tools
lore

Amit Shah

author
#0 lore raw

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(-)
author
#1 lore raw

PATCH 1/6 vl.c: Remove dead assignment

clang-analyzer pointed out the value of 'sockets' is never reused.

CC Andre Przywara <[email protected]>
---
 vl.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)
vl.c +1 -5
index b048e89..e49e7bd 100644
@@ -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
author
#2 lore raw

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
index 02d9180..6e48997 100644
@@ -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
author
#3 lore raw

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
index 511a4ea..8078112 100644
@@ -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
author
#4 lore raw

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
index d05f1f9..6a1a059 100644
@@ -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
author
#5 lore raw

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
index 54b19f8..3a2d44a 100644
@@ -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
author
#6 lore raw

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
index 7624c0f..e04932f 100644
@@ -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
#7 lore raw

[Qemu-devel] Re: [PATCH 5/6] qcow2-refcount: remove dead assignment

In reply to Amit Shah
Quoted 12 lines · Amit Shah

clang-analyzer points out a redundant assignment.

---
  block/qcow2-refcount.c |    1 -
  1 files changed, 0 insertions(+), 1 deletions(-)
block/qcow2-refcount.c +0 -0
index 54b19f8..3a2d44a 100644

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

author
#8 lore raw

[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.

---
  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
index 54b19f8..3a2d44a 100644
@@ -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.

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

Acked-by on v1 2/6
#9 lore raw

[Qemu-devel] Re: [PATCH 2/6] virtio: net: remove dead assignment

In reply to Amit Shah
Quoted 3 lines · Amit Shah

clang-analyzer points out value assigned to 'len' is not used.

Quoted 21 lines
---
 hw/virtio-net.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/virtio-net.c +1 -1
index 02d9180..6e48997 100644
@@ -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
#10 lore raw

Re: [Qemu-devel] [PATCH 1/6] vl.c: Remove dead assignment

In reply to Amit Shah
Quoted 5 lines · Amit Shah

clang-analyzer pointed out the value of 'sockets' is never reused.

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
index b048e89..e49e7bd 100644
@@ -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);
              }
          }