cmd/gpt.c: Fix warning over memset args in allocate_disk_part
PATCH 1/1 cmd/gpt.c: Fix warning over memset args in allocate_disk_part
With clang-3.8 we see:cmd/gpt.c:196:31: warning: 'memset' call operates on objects
of type 'struct disk_part' while the size is based on a different type 'struct disk_part *' [-Wsizeof-pointer-memaccess]
memset(newpart, '\0', sizeof(newpart));
~~~~~~~ ^~~~~~~cmd/gpt.c:196:31: note: did you mean to dereference the
argument to 'sizeof' (and multiply it by the number of elements)?
memset(newpart, '\0', sizeof(newpart));
^~~~~~~As we should have been passing sizeof(*newpart) not sizeof(newpart) here.
--- cmd/gpt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/gpt.c +1 -1
@@ -193,7 +193,7 @@ static struct disk_part *allocate_disk_part(disk_partition_t *info, int partnum) newpart =malloc (sizeof (*newpart));if (!newpart)return ERR_PTR (-ENOMEM ); -memset (newpart,'\0' ,sizeof (newpart)); +memset (newpart,'\0' ,sizeof (*newpart)); newpart->gpt_part_info.start = info->start; newpart->gpt_part_info.size = info->size;
Signature · 1 line
1.9.1
PATCH 1/1 cmd/gpt.c: Fix warning over memset args in allocate_disk_part
Quoted 12 lines · Tom Rini
With clang-3.8 we see:
cmd/gpt.c:196:31: warning: 'memset' call operates on objects
of type 'structdisk_part' while the size is based on a different
type'struct disk_part *' [-Wsizeof-pointer-memaccess] memset(newpart, '\0', sizeof(newpart)); ~~~~~~~ ^~~~~~~ cmd/gpt.c:196:31: note: did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)? memset(newpart, '\0', sizeof(newpart)); ^~~~~~~
Quoted 4 lines
As we should have been passing
sizeof(*newpart)not sizeof(newpart) here.
Agreed. I'm happy to have now read how u-boot can be compiled with clang.
-- Alison
Quoted 27 lines
Cc Lothar Waßmann <[email protected]>Cc Alison Chaiken <[email protected]>Fixes 09a49930e415 ("GPT: read partition table from device into a datastructure")
Signed-off-by Tom Rini <[email protected]>--- cmd/gpt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)cmd/gpt.c +1
-1@@ -193,7 +193,7 @@ static struct disk_part *allocate_disk_part(disk_partition_t *info, int partnum) newpart =malloc (sizeof (*newpart));if (!newpart)return ERR_PTR (-ENOMEM ); -memset (newpart,'\0' ,sizeof (newpart)); +memset (newpart,'\0' ,sizeof (*newpart)); newpart->gpt_part_info.start = info->start;newpart->gpt_part_info.size = info->size;--
1.9.1