From mboxrd@z Thu Jan 1 00:00:00 1970 From: Albert ARIBAUD Date: Wed, 12 Feb 2014 17:33:29 +0100 Subject: [U-Boot] [PATCH] part_efi: fix protective_mbr struct allocation In-Reply-To: References: <1392216053-10344-1-git-send-email-hector.palacios@digi.com> Message-ID: <20140212173329.057a0c87@lilith> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Fabio, On Wed, 12 Feb 2014 12:43:02 -0200, Fabio Estevam wrote: > On Wed, Feb 12, 2014 at 12:40 PM, Hector Palacios > wrote: > > The calloc() call was allocating space for the sizeof the struct > > pointer rather than for the struct contents. > > > > Signed-off-by: Hector Palacios > > --- > > disk/part_efi.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/disk/part_efi.c b/disk/part_efi.c > > index 5dfaf490c89a..7fabec059d7a 100644 > > --- a/disk/part_efi.c > > +++ b/disk/part_efi.c > > @@ -232,7 +232,7 @@ static int set_protective_mbr(block_dev_desc_t *dev_desc) > > legacy_mbr *p_mbr; > > > > /* Setup the Protective MBR */ > > - p_mbr = calloc(1, sizeof(p_mbr)); > > + p_mbr = calloc(1, sizeof(legacy_mbr)); > > What about: > > p_mbr = calloc(1, sizeof(*p_mbr)) ? I don't like the idea of setting p_mbr based on *p_mbr at a time where p_mbr is still undefined. I know that from a C standard perspective this is ok, but I'd rather simply not run any risk and pass sizeof the struct type, not a (non-existent) dereferenced 'value'. > Regards, > > Fabio Estevam Amicalement, -- Albert.