GPT: incomplete initialization in allocate_disk_part
PATCH 1/1 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).
Identified by cppcheck.
--- cmd/gpt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
cmd/gpt.c +2 -2
@@ -190,10 +190,10 @@ 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 =malloc (sizeof (struct disk_part ));if (!newpart)return ERR_PTR (-ENOMEM ); -memset (newpart,'\0' ,sizeof (newpart)); +memset (newpart,'\0' ,sizeof (struct disk_part )); newpart->gpt_part_info.start = info->start; newpart->gpt_part_info.size = info->size;
Signature · 1 line
2.11.0
PATCH 1/1 GPT: incomplete initialization in allocate_disk_part
Quoted 21 lines · Heinrich Schuchardt
memset(newpart, '\0', sizeof(newpart));
only initializes the firest 4 or 8 bytes of *newpart and not the whole structuredisk_part.We should use
sizeof(struct disk_part).Identified by cppcheck.
Fixes 09a49930e41 GPT: read partition table from device into a data structureSigned-off-by Heinrich Schuchardt <[email protected]>--- cmd/gpt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)cmd/gpt.c +0
-0@@ -190,10 +190,10 @@ static void del_gpt_info(void)static struct disk_part *allocate_disk_part (disk_partition_t *info,int partnum) {
cmd/gpt.c static void del_gpt_info(void) · line 199
Quoted 10 lines
cmd/gpt.c +2
-2struct disk_part *newpart; - newpart =malloc (sizeof (*newpart)); + newpart =malloc (sizeof (struct disk_part ));if (!newpart)return ERR_PTR (-ENOMEM ); -memset (newpart,'\0' ,sizeof (newpart)); +memset (newpart,'\0' ,sizeof (struct disk_part )); newpart->gpt_part_info.start = info->start; newpart->gpt_part_info.size = info->size;
Why don't you use calloc() instead and drop the memset completely?
Thanks,
Stefan
PATCH 1/1 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.
---
v2
use calloc as suggested by Stefan
--- cmd/gpt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
cmd/gpt.c +1 -2
@@ -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;
Signature · 1 line
2.11.0
PATCH 1/1 GPT: incomplete initialization in allocate_disk_part
Quoted 27 lines · Heinrich Schuchardt
memset(newpart, '\0', sizeof(newpart));
only initializes the firest 4 or 8 bytes of *newpart and not the whole structuredisk_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 structureCc Stefan Roese <[email protected]>Signed-off-by Heinrich Schuchardt <[email protected]>---
v2
use calloc as suggested by Stefan--- cmd/gpt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)cmd/gpt.c +0
-0@@ -190,10 +190,9 @@ static void del_gpt_info(void)static struct disk_part *allocate_disk_part (disk_partition_t *info,int partnum)
cmd/gpt.c static void del_gpt_info(void) · line 198
Quoted 10 lines
cmd/gpt.c +1
-2{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;
Thanks,
Stefan
PATCH 1/1 GPT: incomplete initialization in allocate_disk_part
Quoted 12 lines · Stefan Roese
Quoted 11 lines · Heinrich Schuchardt
memset(newpart, '\0', sizeof(newpart));
only initializes the firest 4 or 8 bytes of *newpart and not the whole structuredisk_part.We should use
sizeof(struct disk_part).Instead of malloc and memset we can use calloc.
Identified by cppcheck.
Quoted 10 lines
Quoted 10 lines
Fixes 09a49930e41 GPT: read partition table from device into a datastructure
Cc Stefan Roese <[email protected]>Signed-off-by Heinrich Schuchardt <[email protected]>---
v2
use calloc as suggested by Stefan--- cmd/gpt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
PATCH 1/1 GPT: incomplete initialization in allocate_disk_part
In reply to Heinrich SchuchardtQuoted 8 lines · Heinrich Schuchardt
memset(newpart, '\0', sizeof(newpart));
only initializes the firest 4 or 8 bytes of *newpart and not the whole structuredisk_part.We should use
sizeof(struct disk_part).Instead of malloc and memset we can use calloc.
Quoted 8 lines
Identified by cppcheck.
Fixes 09a49930e41 GPT: read partition table from device into a data structureReported-by Coverity (CID: 167228)Cc Stefan Roese <[email protected]>Signed-off-by Heinrich Schuchardt <[email protected]>Reviewed-by Stefan Roese <[email protected]>Reviewed-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170926/bb5baed6/attachment.sig>