> On Jul 4, 2016, at 12:58 PM, Clark Cox <clarkc...@gmail.com> wrote:
> 
> Malloc effectively *never* returns NULL. 

It does seem that malloc returns NULL on error...

#include <stdlib.h>
#include <stdio.h>

int main(int argc, const char * argv[]) {
   size_t need_size = 0x1000000000000;

   char *data = "dummy";      // data ptr is not NULL
   data = malloc(need_size);  // data ptr overwritten

   if(data == NULL) {
       printf("ERROR data == %p\n",data);  // <----- data is NULL
       return 1;
   } else {
       printf("OKAY data != NULL: %p\n",data);
   }
   data[0] = 'c';

   free(data);

   return 0;
}

mtest(3008,0x7fff786d1300) malloc: *** mach_vm_map(size=281474976710656) failed 
(error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
ERROR data == 0x0



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (Xcode-users@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/xcode-users/archive%40mail-archive.com

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

Reply via email to