[U-Boot] [PATCH] part_dos: allocate sector buffer dynamically

Wolfgang Denk wd at denx.de
Tue May 3 14:34:28 CEST 2011


Dear Sergei Shtylyov,

In message <4DBFF300.9010906 at mvista.com> you wrote:
> 
> > Can we please keep the buffer on the stack as before?
> 
>     It will be unsafe. We can't really predict the size of the buffer (unless 
> we postulate that the buffer size won't ever exceed e.g. 4K).

In which way will a buffer allocated on the stack be less safe than
one allocated using malloc()?  Changes to do things wrong (like
forgetting to free the array on return or freeing a bad pointer) are
much higher with malloc(), it seems.

>     I think using stack variables makes the code much more error prone, to the 
> point that U-Boot just crashes when the sector size happens to exceed our 
> buffer size.

This statement makes no sense to me.  Wether the sector size exceeds
the buffer size or not is in no way dependent on where or how you
allocate the buffer - be it on the stack or using malloc().

Umm... you _are_ aware that you can put dynamically sized arrays on
the stack, aren't you?

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Disc space - the final frontier!


More information about the U-Boot mailing list