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

2015-05-06 Thread Clark Smith Cox III

 On May 5, 2015, at 14:19, Michael David Crawford mdcrawf...@gmail.com 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
clark@apple.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2015-05-05 Thread Jens Alfke
The Clang static analyzer will warn about potential calls to malloc(0).

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

malloc(0) returns a pointer, not NULL

2015-05-05 Thread Michael David Crawford
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().

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,

Mike
Michael David Crawford, Consulting Software Engineer
mdcrawf...@gmail.com
http://www.warplife.com/mdc/

   Available for Software Development in the Portland, Oregon Metropolitan
Area.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com