Skip to main content

IAR Embedded Workbench for Arm 9.70.x

CERT-FIO46-C_c

In this section:
Synopsis

Do not access a closed file.

Enabled by default

Yes

Severity/Certainty

Medium/Low

mediumlow.png
Full description

Using the value of a pointer to a FILE object after the associated file is closed is undefined behavior. This check is identical to RESOURCE-double-close.

Coding standards
CERT FIO46-C

Do not access a closed file

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);
  fclose(f1);
} 

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");
  fclose(f1);
}