MISRAC2012-Rule-22.6
In this section:
Synopsis
(Mandatory) The value of a pointer to a FILE shall not be used after the associated stream has been closed
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
A file pointer was found that is used after it has been closed.
Coding standards
- MISRA C:2012 Rule-22.6
(Mandatory) The value of a pointer to a FILE shall not be used after the associated stream has been closed
Code examples
The following code example fails the check and will give a warning:
#include <stdio.h>
void example(void) {
FILE *f1;
f1 = fopen("test_file", "w");
fclose(f1);
fprintf(f1, "Hello, World!\n");
}
The following code example passes the check and will not give a warning about this issue:
#include <stdio.h>
void example(void) {
FILE *f1;
f1 = fopen("test_file", "w");
fprintf(f1, "Hello, World!\n");
fclose(f1);
}