From: Heinrich Schuchardt Date: Thu, 21 Sep 2017 17:03:06 +0000 (+0200) Subject: GPT: incomplete initialization in allocate_disk_part X-Git-Tag: v2017.11-rc1~35 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f66bc0e0beeff7fa27c29f740d2f314d63b3346d;p=u-boot GPT: incomplete initialization in allocate_disk_part memset(newpart, '\0', sizeof(newpart)); only initializes the firest 4 or 8 bytes of *newpart and not the whole structure disk_part. We should use sizeof(struct disk_part). Instead of malloc and memset we can use calloc. Identified by cppcheck. Fixes: 09a49930e41 GPT: read partition table from device into a data structure Reported-by: Coverity (CID: 167228) Cc: Stefan Roese Signed-off-by: Heinrich Schuchardt Reviewed-by: Stefan Roese Reviewed-by: Simon Glass --- diff --git a/cmd/gpt.c b/cmd/gpt.c index 638aa19826..d4406e3120 100644 --- a/cmd/gpt.c +++ b/cmd/gpt.c @@ -190,10 +190,9 @@ static void del_gpt_info(void) static struct disk_part *allocate_disk_part(disk_partition_t *info, int partnum) { struct disk_part *newpart; - newpart = malloc(sizeof(*newpart)); + newpart = calloc(1, sizeof(struct disk_part)); if (!newpart) return ERR_PTR(-ENOMEM); - memset(newpart, '\0', sizeof(newpart)); newpart->gpt_part_info.start = info->start; newpart->gpt_part_info.size = info->size;