mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rob Landley <rob@landley.net>
To: musl@lists.openwall.com
Cc: musl@lists.openwall.com
Subject: Re: malloc(0) behaviour
Date: Tue, 15 Jan 2013 06:17:27 -0600	[thread overview]
Message-ID: <1358252247.32505.23@driftwood> (raw)
In-Reply-To: <20130115002442.GU20323@brightrain.aerifal.cx> (from dalias@aerifal.cx on Mon Jan 14 18:24:42 2013)

On 01/14/2013 06:24:42 PM, Rich Felker wrote:
> > Not indicating that the allocation failed and triggering an assert()
> > when there isn't actually a problem with a legitimately zero length
> > array that had nothing in it? (Both times I debugged why LFS stuff
> > was failing that's what it turned out to be, but I didn't spend too
> > much time on it before just switching the uClibc option on to
> > support it.)
> 
> While in some cases it would be nice to get a fault, you don't usually
> get a fault when trying to access past the end of a length-1 array, so
> why should you expect one when trying to access past the end of a
> "length-0 array"?

Nobody accessed it. They were doing something handwavingly like:

   if (!(array=malloc(sizeof(struct blah)*len))) die();
   for (i=0; i<len; i++) blah();

Which works just fine for len=0 because the for loop doesn't do  
anything... assuming malloc doesn't return 0 and trigger the allocation  
failure check.

(But again, this was ~5 years ago. Haven't tried switching it off  
since.)

> > >except to support buggy and lazy programming.
> >
> > You're defining "lazy" here a "not adding a special case in the
> > caller for every use of malloc()". That's certainly a point of view,
> > but I'm not sure that's the word you want to use for it. "Not
> > sufficiently defensive programming" maybe?
> 
> Well, doing nothing to account for the fact that malloc(0) "failing"
> might not indicate a problematic OOM condition is "lazy" in my book.

Maybe, but it means they're special casing 0, when otherwise it just  
works. (At least on eglibc, and getting people to care about  
portability off glibc remains a thing.)

My point was that requiring them to special case this is not  
necessarily an improvement.

Rob

  reply	other threads:[~2013-01-15 12:17 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-14 17:17 Igmar Palsenberg
2013-01-14 18:05 ` Rich Felker
2013-01-14 22:22   ` Strake
2013-01-14 23:05     ` Rich Felker
2013-01-15  8:32     ` Igmar Palsenberg
2013-01-15 12:53       ` Rob Landley
2013-01-15 22:18         ` Igmar Palsenberg
2013-01-15  8:31   ` Igmar Palsenberg
2013-01-15 11:06     ` Szabolcs Nagy
2013-01-15 12:33       ` Igmar Palsenberg
2013-01-15 13:48         ` Rich Felker
2013-01-15 22:28           ` Igmar Palsenberg
2013-01-15 23:22             ` Rob
2013-01-16  7:46               ` Igmar Palsenberg
2013-01-15 13:46       ` Rich Felker
2013-01-15 12:52     ` Rob Landley
2013-01-14 23:37 ` Rob Landley
2013-01-15  0:24   ` Rich Felker
2013-01-15 12:17     ` Rob Landley [this message]
2013-01-15  9:01   ` Igmar Palsenberg
2013-01-15 12:58     ` Rob Landley
2013-01-15 14:54       ` dladdr() pierre
2013-01-15 18:48         ` dladdr() Rich Felker
2013-01-16 11:00           ` dladdr() pierre
2013-01-16 12:51             ` dladdr() Szabolcs Nagy
2013-01-16 14:24               ` dladdr() musl
2013-01-16 15:20                 ` dladdr() pierre
2013-01-16 16:49                 ` dladdr() Rich Felker
2013-01-16 17:42                   ` dladdr() musl
2013-01-21  2:03                     ` dladdr() Rich Felker
2013-01-21  6:58                       ` dladdr() pierre
2013-01-21 18:35                         ` dladdr() Rich Felker
2013-01-22  6:27                           ` dladdr() pierre
2013-01-22 13:07                             ` dladdr() Szabolcs Nagy
2013-01-22 13:40                               ` dladdr() pierre
2013-01-22 13:51                                 ` dladdr() Rich Felker
2013-01-22 14:59                                   ` dladdr() pierre
2013-01-22 16:11                                     ` dladdr() Szabolcs Nagy
2013-01-22 23:43                                       ` dladdr() Rich Felker

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=1358252247.32505.23@driftwood \
    --to=rob@landley.net \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).