Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Wed, 1 Jan 2014 15:18:59 -0500
From: Rich Felker <dalias@...ifal.cx>
To: musl@...ts.openwall.com
Subject: Re: musl & strndupa?

On Wed, Jan 01, 2014 at 08:07:07PM +0000, Raphael Cohn wrote:
> Rich,
> 
> Thank you for the extremely informative and quick response! I suspect in
> the small, understandable places that use this function in this package it
> should be possible to avoid multiple evaluations (well, at least for this
> version of the code; no g'tee that would hold).
> 
> Out of interest, I presume there's no guarantee that alloca is aligned?

You'd have to consult the compiler for a guarantee, but I think the
intent is that it's suitably aligned for any type, but perhaps not for
extended things like vector operations.

> It's not a feature I've ever used - it seems like a micro-optimisation for
> tight loops that should be made as part of a decision by a higher-level
> language (eg Vala, which, as I understand, doesn't).

The intent of alloca is to allow the programmer to be lazy about
obtaining temporary, "arbitrarily large" storage that will
automatically cease to exist when the caller returns. It's mostly
obsoleted by VLAs (but alloca can do things VLA can't, e.g. when used
in loops), but VLAs are also unsafe in the same way that there's no
way to check for allocation failures or handle them when they occur.
When you really need more than a small reasonable bounded-size buffer,
you need to be using malloc/free and dealing with the ugly failure
cases and cleanup on return...

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.