public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] part_dos: allocate sector buffer dynamically
Date: Tue, 03 May 2011 14:34:28 +0200	[thread overview]
Message-ID: <20110503123428.2E288126DAF@gemini.denx.de> (raw)
In-Reply-To: <4DBFF300.9010906@mvista.com>

Dear Sergei Shtylyov,

In message <4DBFF300.9010906@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!

  reply	other threads:[~2011-05-03 12:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-12 19:23 [U-Boot] [PATCH] part_dos: allocate sector buffer dynamically Sergei Shtylyov
2011-04-30 19:14 ` Wolfgang Denk
2011-05-03 12:20   ` Sergei Shtylyov
2011-05-03 12:34     ` Wolfgang Denk [this message]
2011-05-03 12:50       ` Sergei Shtylyov
2011-05-12 17:35         ` Wolfgang Denk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110503123428.2E288126DAF@gemini.denx.de \
    --to=wd@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox