block/vdi: Fix wrong size in conditionally used memset, memcmp
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
@@ -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
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.
Cc Kevin Wolf<[email protected]>Signed-off-by Stefan Weil<[email protected]>
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@@ -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)
Kevin Wolf
AppliedAm 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.
Cc Kevin Wolf<[email protected]>Signed-off-by Stefan Weil<[email protected]>
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_SIZEmay 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