Felix Singer submitted this change.

View Change


Approvals: build bot (Jenkins): Verified Felix Singer: Looks good to me, approved Angel Pons: Looks good to me, approved
layout.c: Use calloc() to ensure a zeroed layout

No need to malloc() and then do a DIY memset to zero of the
heap. Just use calloc(1, ..) to get a zeroed heap.

Change-Id: Id6cf2c4591aec0620f15d8a39495d2bff6597f96
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/68279
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
---
M layout.c
1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/layout.c b/layout.c
index 0212699..be88428 100644
--- a/layout.c
+++ b/layout.c
@@ -355,14 +355,12 @@

int flashrom_layout_new(struct flashrom_layout **const layout)
{
- *layout = malloc(sizeof(**layout));
+ *layout = calloc(1, sizeof(**layout));
if (!*layout) {
msg_gerr("Error creating layout: %s\n", strerror(errno));
return 1;
}

- const struct flashrom_layout tmp = { 0 };
- **layout = tmp;
return 0;
}


To view, visit change 68279. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Id6cf2c4591aec0620f15d8a39495d2bff6597f96
Gerrit-Change-Number: 68279
Gerrit-PatchSet: 2
Gerrit-Owner: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Felix Singer <felixsinger@posteo.net>
Gerrit-Reviewer: Nikolai Artemiev <nartemiev@google.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-MessageType: merged