Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[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



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:
http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.