Re: malloc was optimized out
Re: malloc was optimized out
- Subject: Re: malloc was optimized out
- From: Carl Hoefs <email@hidden>
- Date: Mon, 04 Jul 2016 13:20:03 -0700
> On Jul 4, 2016, at 12:58 PM, Clark Cox <email@hidden> 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 (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden