Re: Program crashes when executed normally, but runs w/o trouble in the Debugger
Re: Program crashes when executed normally, but runs w/o trouble in the Debugger
- Subject: Re: Program crashes when executed normally, but runs w/o trouble in the Debugger
- From: Cameron Kerr <email@hidden>
- Date: Fri, 1 Jul 2005 11:24:28 +1200
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 s (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:
This email sent to email@hidden