Skip to contentSkip to conversation

block/vdi: Fix wrong size in conditionally used memset, memcmp

PATCH Applied Stefan Weil 3 participants 3 messages Feb 4, 2011 – Feb 7, 2011 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/vdi: Fix wrong size in conditionally used memset, memcmp

Error report from cppcheck:
block/vdi.c:122: error: Using sizeof for array given as function argument returns the size of pointer. block/vdi.c:128: error: Using sizeof for array given as function argument returns the size of pointer.

Fix both by setting the correct size.

The buggy code is only used when QEMU is build without uuid support. The bug is not critical, so there is no urgent need to apply it to old versions of QEMU.

---
 block/vdi.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
block/vdi.c +2 -2
index 83b9c04..083266e 100644
@@ -119,13 +119,13 @@ void uuid_unparse(const uuid_t uu, char *out);
 #if !defined(CONFIG_UUID)
 void uuid_generate(uuid_t out)
 {
-    memset(out, 0, sizeof(out));
+    memset(out, 0, sizeof(uuid_t));
 }
 
 int uuid_is_null(const uuid_t uu)
 {
     uuid_t null_uuid = { 0 };
-    return memcmp(uu, null_uuid, sizeof(uu)) == 0;
+    return memcmp(uu, null_uuid, sizeof(uuid_t)) == 0;
 }
 
 void uuid_unparse(const uuid_t uu, char *out)
Signature · 1 line
1.7.2.3
#1 lore raw
Quoted 4 lines · Stefan Weil

Error report from cppcheck:
block/vdi.c:122: error: Using sizeof for array given as function argument returns the size of pointer. block/vdi.c:128: error: Using sizeof for array given as function argument returns the size of pointer.

Quoted 9 lines

Fix both by setting the correct size.

The buggy code is only used when QEMU is build without uuid support. The bug is not critical, so there is no urgent need to apply it to old versions of QEMU.

Huh, I wouldn't have thought this was the case. I almost feel that doing a #define UUID_SIZE may be better because sizeof(typeof(v)) != sizeof(v) is weird even by C standards.

Regards,

Anthony Liguori

Quoted 25 lines
---
  block/vdi.c |    4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)
block/vdi.c +2 -2
index 83b9c04..083266e 100644
@@ -119,13 +119,13 @@ void uuid_unparse(const uuid_t uu, char *out);
  #if !defined(CONFIG_UUID)
  void uuid_generate(uuid_t out)
  {
-    memset(out, 0, sizeof(out));
+    memset(out, 0, sizeof(uuid_t));
  }
 
  int uuid_is_null(const uuid_t uu)
  {
      uuid_t null_uuid = { 0 };
-    return memcmp(uu, null_uuid, sizeof(uu)) == 0;
+    return memcmp(uu, null_uuid, sizeof(uuid_t)) == 0;
  }
 
  void uuid_unparse(const uuid_t uu, char *out)
Applied
#2 lore raw

Am 04.02.2011 21:19, schrieb Anthony Liguori:

Quoted 5 lines · Stefan Weil
Quoted 4 lines

Error report from cppcheck:
block/vdi.c:122: error: Using sizeof for array given as function argument returns the size of pointer. block/vdi.c:128: error: Using sizeof for array given as function argument returns the size of pointer.

Quoted 8 lines
Quoted 8 lines

Fix both by setting the correct size.

The buggy code is only used when QEMU is build without uuid support. The bug is not critical, so there is no urgent need to apply it to old versions of QEMU.

Thanks, applied to the block branch.

Quoted 3 lines

Huh, I wouldn't have thought this was the case. I almost feel that doing a #define UUID_SIZE may be better because sizeof(typeof(v)) != sizeof(v) is weird even by C standards.

I think typeof(uu) is actually unsigned char*, not unsigned char[16]. Strange semantics anyway...

Kevin