• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: malloc(0) returns a pointer, not NULL
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: malloc(0) returns a pointer, not NULL


  • Subject: Re: malloc(0) returns a pointer, not NULL
  • From: Clark Smith Cox III <email@hidden>
  • Date: Tue, 05 May 2015 23:17:22 -0700

> On May 5, 2015, at 14:19, Michael David Crawford <email@hidden> wrote:
>
> This came as news to me.
>
> The C spec says this is implementation-definited; malloc(0 may return
> either NULL or it may return a pointer that can subsequently be passed
> to free().

Note that even when it does return NULL, that is still a “pointer that can subsequently be passed to free()” (i.e. free(NULL) is perfectly well-defined).

> In the case of the bug I'm looking at just now, it's an error in my
> code, so I now have:
>
> assert( 0 != bytes );
> ptr = malloc( bytes );
>
> Just thought you'd like to know,


--
Clark Smith Cox III
email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >malloc(0) returns a pointer, not NULL (From: Michael David Crawford <email@hidden>)

  • Prev by Date: Re: Help: NSScrollView is resizing its documentView down to (0, 0)
  • Next by Date: NSNotification coalescing - which one gets through?
  • Previous by thread: Re: malloc(0) returns a pointer, not NULL
  • Next by thread: Re: Issues with implementing WYWIWYG font menu
  • Index(es):
    • Date
    • Thread