delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/11/06/19:55:12

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Sun, 6 Nov 2005 19:55:02 -0500
From: Christopher Faylor <cgf-no-personal-reply-please AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: BUG: alternatives
Message-ID: <20051107005502.GA8754@trixie.casa.cgf.cx>
Reply-To: cygwin AT cygwin DOT com
References: <436CF5E9 DOT 30106 AT cwilson DOT fastmail DOT fm> <001201c5e244$c9e50490$020aa8c0 AT DFW5RB41> <436D9993 DOT 7050100 AT cwilson DOT fastmail DOT fm> <20051106134339 DOT GA24549 AT trixie DOT casa DOT cgf DOT cx> <436E50DE DOT 3070405 AT cwilson DOT fastmail DOT fm>
Mime-Version: 1.0
In-Reply-To: <436E50DE.3070405@cwilson.fastmail.fm>
User-Agent: Mutt/1.5.8i

On Sun, Nov 06, 2005 at 01:52:14PM -0500, Charles Wilson wrote:
>Christopher Faylor wrote:
>
>>A signal shouldn't cause a truncated read when retrieving data from
>>disk on cygwin or linux.
>
>ACK.
>
>>I think the only sane way to handle this is to put the read in a loop
>>and realloc the buffer as needed as long as the read continues to return
>>'>0'.
>
>Ok.
>
>>It's obviously pretty racy to get the size of the file and then expect that
>>you'll be able to read in exactly that many bytes.
>
>ACK.
>
>Revised patch attached.  I'm wondering, tho, about the advisability of 
>using alloca'ed (rather than malloc'ed) memory to hold the contents of a 
>file of unrestricted size.  Aren't there limits on the available space 
>within a single stack frame?  Does it make sense (is it legal) to alloca 
>40k or 50k or 500k? of memory?
>
>Granted, most /var/lib/alternatives files are going to be fairly small 
>(< 1k) but there's no guarantee of that...

I have mixed feelings about alloca, personally.  I use it all of the time but
it is always with some trepidation because, AFAIK, the failure condition for
alloca is a SEGV.  OTOH, it is very convenient.

In this case, however, I think you really want to use realloc.  You could even
rely on the fact that realloc(NULL, n) is equivalent to malloc(n).

cgf

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019