• 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 was optimized out
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: malloc was optimized out
      • From: Dmitry Markman <email@hidden>
    • Re: malloc was optimized out
      • From: Dmitry Markman <email@hidden>
References: 
 >malloc was optimized out (From: Dmitry Markman <email@hidden>)
 >Re: malloc was optimized out (From: Clark Cox <email@hidden>)

  • Prev by Date: Re: malloc was optimized out
  • Next by Date: Re: malloc was optimized out
  • Previous by thread: Re: malloc was optimized out
  • Next by thread: Re: malloc was optimized out
  • Index(es):
    • Date
    • Thread