• 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
Program crashes when executed normally, but runs w/o trouble in the Debugger
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Program crashes when executed normally, but runs w/o trouble in the Debugger


  • Subject: Program crashes when executed normally, but runs w/o trouble in the Debugger
  • From: "Lorance, Ted" <email@hidden>
  • Date: Thu, 30 Jun 2005 16:01:10 -0700
  • Thread-topic: Program crashes when executed normally, but runs w/o trouble in the Debugger

I apologize in advance if this is one of those stupid simple things, but I am teaching myself to program in C for the Mac by porting an old curve fitting program I use from time to time.  I was defeated in my attempt to use the built-in Menu:Open... function in XCode, so I fell back on using fopen after acquiring the filename from a textbox in the user interface.  This worked splendidly all through development (when I was running the program in the Debugger), but neither the "development" or "deployment" builds can do any file access w/o crashing.
The error in both cases occurred while interacting with libSystem.B.dylib, and both instances are Bad Access exceptions (Exception: EXC_BAD_ACCESS (0x0001); Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000000).  One of the performance tools (which also all crashed, while the Debugger doesn't seem to notice the problem) returned the following message: "/Programming/XCode_Projects/Grapher/Exponential Fitter.app/Contents/MacOS/Exponential Fitter accessed memory at 0x00000000 illegally. It probably tried to dereference a NULL pointer."

I am sure I am trying to do something stupid, and I could probably figure it out myself if it failed the same way in the Debugger that it does normally.

Any assistance would be appreciated; I have a fair amount of programming experience, but I am a chemist, not a programmer, and I fear it shows.

  Thanks,
  Dr. Ted Lorance


The offending code is as follows (the other file access routine is similar):

OSStatus fgetLaserData (WindowRef window)
{
    const ControlID kFileName = { kCommandSignature, kFileNameFieldID };

    ControlRef cr_FileName;
    CFStringRef FileName_text;
    OSStatus err = noErr;
    char * buffer;
    int flag;
    char temp[20];
    char localBuffer[60];
    int i=0;
    FILE * in_file;
    Boolean success;

    buffer = getenv ("PWD");

    err = GetControlByID (window, &kFileName, &cr_FileName);
    require_noerr_quiet (err, CantGetControl);
    err = GetControlData (cr_FileName, 0, kControlEditTextCFStringTag, sizeof(CFStringRef), &FileName_text, NULL);
    require_noerr (err, CantGetControlData);
    success = CFStringGetCString(FileName_text, localBuffer, 40, kCFStringEncodingMacRoman);
    printf("%s\n",localBuffer);

    strcat(buffer,"/\0");
    printf("%s\n",buffer);
    strcat(buffer,localBuffer);
    printf("%s\n",buffer);

    in_file = fopen(buffer,"rt");
    if (in_file==NULL)
    {
        printf("File not found.\n");
        return err;
    }
    else
    {
        printf("File found. All is well. Nothing to see here.\n");
    }

    do {
        flag=0;
        fscanf (in_file, "%s", &temp);
etc.

 _______________________________________________
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: Program crashes when executed normally, but runs w/o trouble in the Debugger
      • From: Ladd Van Tol <email@hidden>
    • Re: Program crashes when executed normally, but runs w/o trouble in the Debugger
      • From: Cameron Kerr <email@hidden>
  • Prev by Date: Re: xcconfig files and ZeroLink
  • Next by Date: Re: fopen
  • Previous by thread: Xcode 2.1 and group renaming
  • Next by thread: Re: Program crashes when executed normally, but runs w/o trouble in the Debugger
  • Index(es):
    • Date
    • Thread