• 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: Calling fopen() from a simple C++ program in Xcode 5.0.2 raises EXC_BAD_ACCESS, code=2
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling fopen() from a simple C++ program in Xcode 5.0.2 raises EXC_BAD_ACCESS, code=2


  • Subject: Re: Calling fopen() from a simple C++ program in Xcode 5.0.2 raises EXC_BAD_ACCESS, code=2
  • From: Dan Korn <email@hidden>
  • Date: Tue, 24 Dec 2013 12:31:14 -0600

Thanks Ken.  That was it.  That also explains why removing the code that declares that variable prevents the crash.

FWIW, the same program built and debugged in Visual Studio raises a stack overflow exception, which is much more helpful feedback than just "bad access."

I guess I failed at my little C++ 101 project here.  (I'm also getting zero back from the call to fread; I need to put specify the item size of 1 before the size in bytes.)

By the way, what I'm really trying to do is download a very large .dmg file that was my setup from my old MacBook Pro, so that I can restore it to a partition on the new one.  It's on a server which apparently has no limit on the size of files you can upload, but does have a limit on the size of a file you can download.

Thanks again,
Dan

On Mon, Dec 23, 2013 at 11:45 PM, Ken Thomases <email@hidden> wrote:
On Dec 23, 2013, at 9:49 PM, Dan Korn wrote:

    const size_t inBufferSize = 10000000; // about 10 MB

        char buffer[inBufferSize];

The default stack size is 8MB.  Your "buffer" variable exceeds that.  I suspect that's the problem.  Don't put such large buffers on the stack.  Allocate them on the heap.

Regards,
Ken




On Mon, Dec 23, 2013 at 11:45 PM, Ken Thomases <email@hidden> wrote:
On Dec 23, 2013, at 9:49 PM, Dan Korn wrote:

    const size_t inBufferSize = 10000000; // about 10 MB

        char buffer[inBufferSize];

The default stack size is 8MB.  Your "buffer" variable exceeds that.  I suspect that's the problem.  Don't put such large buffers on the stack.  Allocate them on the heap.

Regards,
Ken


 _______________________________________________
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: Calling fopen() from a simple C++ program in Xcode 5.0.2 raises EXC_BAD_ACCESS, code=2
      • From: Jean-Daniel Dupas <email@hidden>
    • Re: Calling fopen() from a simple C++ program in Xcode 5.0.2 raises EXC_BAD_ACCESS, code=2
      • From: Jens Alfke <email@hidden>
References: 
 >Calling fopen() from a simple C++ program in Xcode 5.0.2 raises EXC_BAD_ACCESS, code=2 (From: Dan Korn <email@hidden>)
 >Re: Calling fopen() from a simple C++ program in Xcode 5.0.2 raises EXC_BAD_ACCESS, code=2 (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Calling fopen() from a simple C++ program in Xcode 5.0.2 raises EXC_BAD_ACCESS, code=2
  • Next by Date: Re: Calling fopen() from a simple C++ program in Xcode 5.0.2 raises EXC_BAD_ACCESS, code=2
  • Previous by thread: Re: Calling fopen() from a simple C++ program in Xcode 5.0.2 raises EXC_BAD_ACCESS, code=2
  • Next by thread: Re: Calling fopen() from a simple C++ program in Xcode 5.0.2 raises EXC_BAD_ACCESS, code=2
  • Index(es):
    • Date
    • Thread