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: 09a49930e4 GPT: read partition table from device into a data structure
Reported-by: Coverity (CID: 167228)
Cc: Stefan Roese <sr@denx.de>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Heinrich Schuchardt 2017-09-21 19:03:06 +02:00 committed by Tom Rini
parent 0cc8c3064d
commit f66bc0e0be

View file

@ -190,10 +190,9 @@ static void del_gpt_info(void)
static struct disk_part *allocate_disk_part(disk_partition_t *info, int partnum) static struct disk_part *allocate_disk_part(disk_partition_t *info, int partnum)
{ {
struct disk_part *newpart; struct disk_part *newpart;
newpart = malloc(sizeof(*newpart)); newpart = calloc(1, sizeof(struct disk_part));
if (!newpart) if (!newpart)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
memset(newpart, '\0', sizeof(newpart));
newpart->gpt_part_info.start = info->start; newpart->gpt_part_info.start = info->start;
newpart->gpt_part_info.size = info->size; newpart->gpt_part_info.size = info->size;