Fusengammu
Registered
Hello, I'm doing some calculations for my master's thesis, and I think I found a bug in gcc/g++. So can some knowledgeable person tell me whether it is/isn't a bug, and if so, should I report it to Apple?
So I boiled the problem down to 2 simple programs, one buggy and the other not:
fileTestB <filename> <param which causes bug>
and
fileTestNB <filename> <param which doesn't causes bug>
The program just tells you whether filename exists or not. fileTestB (the buggy one) tells me that a non-existent file exists if I give the third argument, while fileTestNB (Not buggy) tells me that a non-existent file doesn't exist whether I give the third param or not.
The buggy output looks like: (a file called "foo" doesn't exist)
****** ~ $ fileTestB foo argv3
****** PRINTING foo CAUSES BUG
****** foo is a regular file
****** ~ $ fileTestB foo
****** foo is a NOT a regular file
while the non-buggy output looks like
****** ~ $ fileTestNB foo argv3
****** PRINTING foo CAUSES NO BUG
****** foo is a NOT a regular file
****** ~ $ fileTestNB foo
****** foo is a NOT a regular file
The source code for the buggy and non-buggy programs are:
/******** begin code for "fileTestB" ********/
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
int fexists(char *);
int main(int argc, char** argv)
{
if( argc < 2 )
{
fprintf(stderr, "fileTests <file or dir name> <3rd arg causes BUG>¥n");
exit(1);
}
if( argc == 3 )
{
// giving a 3rd argument causes BUG
printf(" PRINTING %s CAUSES BUG¥n", argv[1]);
}
if( fexists(argv[1]) )
{
printf("%s is a regular file¥n", argv[1]);
}
else
{
printf("%s is a NOT a regular file¥n", argv[1]);
}
}
int fexists(char *fname)
{
struct stat buffer;
stat(fname, &buffer);
return S_ISREG(buffer.st_mode);
}
/******** end code for "fileTestB" ********/
/******** begin code for "fileTestNB" ********/
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
int main(int argc, char** argv)
{
if( argc < 2 )
{
fprintf(stderr, "fileTests <file or dir name> <3rd arg causes NO BUG>¥n");
exit(1);
}
if( argc == 3 )
{
// giving a 3rd argument causes NO BUG
printf(" PRINTING %s CAUSES NO BUG¥n", argv[1]);
}
struct stat buffer;
stat(argv[1], &buffer);
if( S_ISREG(buffer.st_mode) )
{
printf("%s is a regular file¥n", argv[1]);
}
else
{
printf("%s is a NOT a regular file¥n", argv[1]);
}
}
/******** end code for "fileTestB" ********/
I'm using OS X 10.3.9 on a Dual 2.5GHz G5.
thanx
So I boiled the problem down to 2 simple programs, one buggy and the other not:
fileTestB <filename> <param which causes bug>
and
fileTestNB <filename> <param which doesn't causes bug>
The program just tells you whether filename exists or not. fileTestB (the buggy one) tells me that a non-existent file exists if I give the third argument, while fileTestNB (Not buggy) tells me that a non-existent file doesn't exist whether I give the third param or not.
The buggy output looks like: (a file called "foo" doesn't exist)
****** ~ $ fileTestB foo argv3
****** PRINTING foo CAUSES BUG
****** foo is a regular file
****** ~ $ fileTestB foo
****** foo is a NOT a regular file
while the non-buggy output looks like
****** ~ $ fileTestNB foo argv3
****** PRINTING foo CAUSES NO BUG
****** foo is a NOT a regular file
****** ~ $ fileTestNB foo
****** foo is a NOT a regular file
The source code for the buggy and non-buggy programs are:
/******** begin code for "fileTestB" ********/
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
int fexists(char *);
int main(int argc, char** argv)
{
if( argc < 2 )
{
fprintf(stderr, "fileTests <file or dir name> <3rd arg causes BUG>¥n");
exit(1);
}
if( argc == 3 )
{
// giving a 3rd argument causes BUG
printf(" PRINTING %s CAUSES BUG¥n", argv[1]);
}
if( fexists(argv[1]) )
{
printf("%s is a regular file¥n", argv[1]);
}
else
{
printf("%s is a NOT a regular file¥n", argv[1]);
}
}
int fexists(char *fname)
{
struct stat buffer;
stat(fname, &buffer);
return S_ISREG(buffer.st_mode);
}
/******** end code for "fileTestB" ********/
/******** begin code for "fileTestNB" ********/
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
int main(int argc, char** argv)
{
if( argc < 2 )
{
fprintf(stderr, "fileTests <file or dir name> <3rd arg causes NO BUG>¥n");
exit(1);
}
if( argc == 3 )
{
// giving a 3rd argument causes NO BUG
printf(" PRINTING %s CAUSES NO BUG¥n", argv[1]);
}
struct stat buffer;
stat(argv[1], &buffer);
if( S_ISREG(buffer.st_mode) )
{
printf("%s is a regular file¥n", argv[1]);
}
else
{
printf("%s is a NOT a regular file¥n", argv[1]);
}
}
/******** end code for "fileTestB" ********/
I'm using OS X 10.3.9 on a Dual 2.5GHz G5.
thanx