Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



On 1/07/2005, at 11:01 AM, Lorance, Ted wrote:

It would be advisable to create these on the heap, rather than on the stack (ie, using malloc() and free()). There is only so much space on the stack, although 80 bytes should still fit fine.

    char temp[20];
    char localBuffer[60];


Here you should use getwd() instead of getenv, as PWD will not always be set. It may well be why you are crashing, as you're not testing for errors!

buffer = getenv ("PWD");


When printing debugging statements, always print to stderr, as stderr is unbuffered, and will be printed immediately. So use fprintf ( stderr, ...)

If you don't, you can get a wrong impression of where a program is crashing, if you go by the printf output.

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


Here you're assuming. You should use x-man-page://perror

    in_file = fopen(buffer,"rt");
    if (in_file==NULL)
    {


You should use %19s (temp is 20 characters, so that's 19 characters and the terminating nil) here, and fnscanf, otherwise you can overflow the buffer, and crash.

fscanf (in_file, "%s", &temp);

-- Cameron Kerr Telecommunications Teaching Fellow & SysAdmin email@hidden

_______________________________________________
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
References: 
 >Program crashes when executed normally, but runs w/o trouble in the Debugger (From: "Lorance, Ted" <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.