Skip to main content

IAR Embedded Workbench for RL78 5.20

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

mediummedium.png
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);
}