* [U-Boot] [PATCH 1/1] GPT: incomplete initialization in allocate_disk_part
@ 2017-09-21 10:51 Heinrich Schuchardt
2017-09-21 11:01 ` Stefan Roese
0 siblings, 1 reply; 6+ messages in thread
From: Heinrich Schuchardt @ 2017-09-21 10:51 UTC (permalink / raw)
To: u-boot
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.
Fixes: 09a49930e41 GPT: read partition table from device into a data structure
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
cmd/gpt.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/cmd/gpt.c b/cmd/gpt.c
index 638aa19826..a9c562123f 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -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;
--
2.11.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH 1/1] GPT: incomplete initialization in allocate_disk_part
2017-09-21 10:51 [U-Boot] [PATCH 1/1] GPT: incomplete initialization in allocate_disk_part Heinrich Schuchardt
@ 2017-09-21 11:01 ` Stefan Roese
2017-09-21 17:03 ` Heinrich Schuchardt
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Roese @ 2017-09-21 11:01 UTC (permalink / raw)
To: u-boot
On 21.09.2017 12:51, Heinrich Schuchardt wrote:
> 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.
>
> Fixes: 09a49930e41 GPT: read partition table from device into a data structure
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> cmd/gpt.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/cmd/gpt.c b/cmd/gpt.c
> index 638aa19826..a9c562123f 100644
> --- a/cmd/gpt.c
> +++ b/cmd/gpt.c
> @@ -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;
Why don't you use calloc() instead and drop the memset completely?
Thanks,
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH 1/1] GPT: incomplete initialization in allocate_disk_part
2017-09-21 11:01 ` Stefan Roese
@ 2017-09-21 17:03 ` Heinrich Schuchardt
2017-09-22 5:24 ` Stefan Roese
2017-09-27 2:45 ` [U-Boot] [U-Boot, " Tom Rini
0 siblings, 2 replies; 6+ messages in thread
From: Heinrich Schuchardt @ 2017-09-21 17:03 UTC (permalink / raw)
To: u-boot
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
Cc: Stefan Roese <sr@denx.de>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
v2
use calloc as suggested by Stefan
---
cmd/gpt.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
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;
--
2.11.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH 1/1] GPT: incomplete initialization in allocate_disk_part
2017-09-21 17:03 ` Heinrich Schuchardt
@ 2017-09-22 5:24 ` Stefan Roese
2017-09-25 2:14 ` Simon Glass
2017-09-27 2:45 ` [U-Boot] [U-Boot, " Tom Rini
1 sibling, 1 reply; 6+ messages in thread
From: Stefan Roese @ 2017-09-22 5:24 UTC (permalink / raw)
To: u-boot
On 21.09.2017 19:03, Heinrich Schuchardt wrote:
> 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
> Cc: Stefan Roese <sr@denx.de>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> v2
> use calloc as suggested by Stefan
> ---
> cmd/gpt.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> 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;
>
Reviewed-by: Stefan Roese <sr@denx.de>
Thanks,
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH 1/1] GPT: incomplete initialization in allocate_disk_part
2017-09-22 5:24 ` Stefan Roese
@ 2017-09-25 2:14 ` Simon Glass
0 siblings, 0 replies; 6+ messages in thread
From: Simon Glass @ 2017-09-25 2:14 UTC (permalink / raw)
To: u-boot
On 21 September 2017 at 23:24, Stefan Roese <sr@denx.de> wrote:
> On 21.09.2017 19:03, Heinrich Schuchardt wrote:
>>
>> 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
>> Cc: Stefan Roese <sr@denx.de>
>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>> ---
>> v2
>> use calloc as suggested by Stefan
>> ---
>> cmd/gpt.c | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
Reviewed-by: Simon Glass <sjg@chromium.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [U-Boot] [U-Boot, 1/1] GPT: incomplete initialization in allocate_disk_part
2017-09-21 17:03 ` Heinrich Schuchardt
2017-09-22 5:24 ` Stefan Roese
@ 2017-09-27 2:45 ` Tom Rini
1 sibling, 0 replies; 6+ messages in thread
From: Tom Rini @ 2017-09-27 2:45 UTC (permalink / raw)
To: u-boot
On Thu, Sep 21, 2017 at 07:03:06PM +0200, Heinrich Schuchardt wrote:
> 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 <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>
Applied to u-boot/master, thanks!
--
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>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-09-27 2:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-21 10:51 [U-Boot] [PATCH 1/1] GPT: incomplete initialization in allocate_disk_part Heinrich Schuchardt
2017-09-21 11:01 ` Stefan Roese
2017-09-21 17:03 ` Heinrich Schuchardt
2017-09-22 5:24 ` Stefan Roese
2017-09-25 2:14 ` Simon Glass
2017-09-27 2:45 ` [U-Boot] [U-Boot, " Tom Rini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.