diff mbox series

[U-Boot] cmd/gpt.c: Fix warning over memset args in allocate_disk_part

Message ID 1505476942-14426-1-git-send-email-trini@konsulko.com
State Superseded
Delegated to: Tom Rini
Headers show
Series [U-Boot] cmd/gpt.c: Fix warning over memset args in allocate_disk_part | expand

Commit Message

Tom Rini Sept. 15, 2017, 12:02 p.m. UTC
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.

Cc: Lothar Waßmann <LW@karo-electronics.de>
Cc: Alison Chaiken <alison@peloton-tech.com>
Fixes: 09a49930e415 ("GPT: read partition table from device into a data structure")
Signed-off-by: Tom Rini <trini@konsulko.com>
---
 cmd/gpt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Alison Chaiken Sept. 17, 2017, 1:42 a.m. UTC | #1
On Fri, Sep 15, 2017 at 5:02 AM, Tom Rini <trini@konsulko.com> wrote:

> 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.
>
>
Agreed.  I'm happy to have now read how u-boot can be compiled with clang.

-- Alison


> Cc: Lothar Waßmann <LW@karo-electronics.de>
> Cc: Alison Chaiken <alison@peloton-tech.com>
> Fixes: 09a49930e415 ("GPT: read partition table from device into a data
> structure")
> Signed-off-by: Tom Rini <trini@konsulko.com>
> ---
>  cmd/gpt.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/cmd/gpt.c b/cmd/gpt.c
> index 638aa198267b..701a1c1d6cd1 100644
> --- a/cmd/gpt.c
> +++ b/cmd/gpt.c
> @@ -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
>
>
diff mbox series

Patch

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 638aa198267b..701a1c1d6cd1 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -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;