Can the following code result in undefined behavior?
FILE *fp;
fopen_s(&fp, "abc.bin", "rb");
fclose(fp);
fclose(fp); // accidentally closed an already closed file.
I know that calling free on an already freed up array results in UB. Hence I ask.
Can the following code result in undefined behavior?
FILE *fp;
fopen_s(&fp, "abc.bin", "rb");
fclose(fp);
fclose(fp); // accidentally closed an already closed file.
I know that calling free on an already freed up array results in UB. Hence I ask.
Quote from man fclose:
The behaviour of fclose() is undefined if the stream parameter is an illegal pointer, or is a descriptor already passed to a previous invocation of fclose().
So yes, it is undefined behavior.