From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4446 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: musl & strndupa? Date: Wed, 1 Jan 2014 15:18:59 -0500 Message-ID: <20140101201859.GQ24286@brightrain.aerifal.cx> References: <20140101195411.GP24286@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1388607548 28425 80.91.229.3 (1 Jan 2014 20:19:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 1 Jan 2014 20:19:08 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4450-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jan 01 21:19:15 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1VySG0-0007pH-QX for gllmg-musl@plane.gmane.org; Wed, 01 Jan 2014 21:19:12 +0100 Original-Received: (qmail 26560 invoked by uid 550); 1 Jan 2014 20:19:12 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 26552 invoked from network); 1 Jan 2014 20:19:11 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:4446 Archived-At: 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