Talk:Checking if a file exists in Open C and C++
I have found bug in the function OpenCFileExists() and OpenCppFileExists().
bool OpenCFileExists(const char* filename)
FILE* fp = NULL;
//this will fail if more capabilities to read the
//contents of the file is required (e.g. \private\...)
fp = fopen(filename, "r");
if(fp != NULL)
fclose(fp); /* BUG -- This fclose() function will call when fp=NULL only. Hence, It will crash with Segmentation fault. */
Same mistake in OpenCppFileExists() function also.- Pankaj Choudhary
talk) 12:25, 29 October 2013 (EET)(
Hamishwillee - Pankaj - its a wiki
Generally this is a wiki, so if you're sure that the code is incorrect you can edit it yourself!
So you're saying that the second call of fclose will cause a fault - I would have thought calling fclose on "nothing" wouldn't do anything. If you're right then removing this line should fix the problem right?
talk) 06:46, 5 November 2013 (EET)(