Good day,
I had written some code in C two Linux systems which was working great on them for months, no errors and very fast.
One was an AMD processor and I compiled that code with the newest gcc (3.x). The other was a dual PIII machine and I compiled that with the newest Intel compiler for Linux.
I had no errors and no issues with the code.
I have since moved and no longer have those machines. Instead I now have a FreeBSD machine. This machine is an AMD machine, but it has gcc 2.95.4.
My code compiles fine with no errors, and then here is the annoying part:
Out of 10 times being run, it will work 8 or 9 of those, but occassionally will seg fault out and dump core.
At first I thought I had traced the issue down to where if a file that it needed to create was already there, then it wouldn't crash, but if it had to create it, then it would crash... But that is not the case after further investigation.
I recompiled the code with "gcc -g" to and then got it to dump core and ran the program and the core through gdb.
It game me:
#0 0x8048f4e in analyzeThis (fileName=0x32393839, returnString=0x32373638 <Address 0x32373638 out of bounds>)
at analyze.c:393
393 printf("Filename: %s\n", *fileName);
Line 393 is where I added in a line to see what it saw as the filename getting passed in. But it looks like it is saying the real issue is with the returnString reference being out of bounds.
This is all confusing to me since it all worked perfectly on the other systems, with no change in the code at all.
The "analyzeThis" function that it refers to is called like this:
char analysisData[100];
analyzeThis(&argv[1], analysisData);
Then the function itself, very truncated than the one I have, looks like this:
char *analyzeThis(char *fileName[], char *returnString)
{
FILE *pFile;
printf("Filename: %s\n", *fileName);
/*I have another function that gets called earlier in the program that handles the files in the exact same way and it never dies*/
pFile = fopen(*fileName, "r"
if (pFile == NULL){
perror("Error opening file"
printf("there was an error opening the file, we are leaving now\n"
exit(1);
}
else {
/*do some stuff */
}
/*these are obviously acted on in the function, but it is large and I don't really want all of the code in here - this is the stuff it is failing on)*/
sprintf(returnString,"A: %f\nB: %s\n",myA, myB);
return returnString;
}
I don't know if I just have really poor programming style and the times it was all working on the other systems was just because those compilers are a lot more friendly than this one? Or if it is just some basic differences in the OS/compiler versions.
Any help or suggestions would make my week.
Thanks
I had written some code in C two Linux systems which was working great on them for months, no errors and very fast.
One was an AMD processor and I compiled that code with the newest gcc (3.x). The other was a dual PIII machine and I compiled that with the newest Intel compiler for Linux.
I had no errors and no issues with the code.
I have since moved and no longer have those machines. Instead I now have a FreeBSD machine. This machine is an AMD machine, but it has gcc 2.95.4.
My code compiles fine with no errors, and then here is the annoying part:
Out of 10 times being run, it will work 8 or 9 of those, but occassionally will seg fault out and dump core.
At first I thought I had traced the issue down to where if a file that it needed to create was already there, then it wouldn't crash, but if it had to create it, then it would crash... But that is not the case after further investigation.
I recompiled the code with "gcc -g" to and then got it to dump core and ran the program and the core through gdb.
It game me:
#0 0x8048f4e in analyzeThis (fileName=0x32393839, returnString=0x32373638 <Address 0x32373638 out of bounds>)
at analyze.c:393
393 printf("Filename: %s\n", *fileName);
Line 393 is where I added in a line to see what it saw as the filename getting passed in. But it looks like it is saying the real issue is with the returnString reference being out of bounds.
This is all confusing to me since it all worked perfectly on the other systems, with no change in the code at all.
The "analyzeThis" function that it refers to is called like this:
char analysisData[100];
analyzeThis(&argv[1], analysisData);
Then the function itself, very truncated than the one I have, looks like this:
char *analyzeThis(char *fileName[], char *returnString)
{
FILE *pFile;
printf("Filename: %s\n", *fileName);
/*I have another function that gets called earlier in the program that handles the files in the exact same way and it never dies*/
pFile = fopen(*fileName, "r"
if (pFile == NULL){
perror("Error opening file"
printf("there was an error opening the file, we are leaving now\n"
exit(1);
}
else {
/*do some stuff */
}
/*these are obviously acted on in the function, but it is large and I don't really want all of the code in here - this is the stuff it is failing on)*/
sprintf(returnString,"A: %f\nB: %s\n",myA, myB);
return returnString;
}
I don't know if I just have really poor programming style and the times it was all working on the other systems was just because those compilers are a lot more friendly than this one? Or if it is just some basic differences in the OS/compiler versions.
Any help or suggestions would make my week.
Thanks