Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC2012-Rule-22.3

In this section:
Synopsis

(Required) The same file shall not be open for read and write access at the same time on different streams.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

A file was found that is open for read and write access at the same time on different streams.

Coding standards
MISRA C:2012 Rule-22.3

(Required) The same file shall not be open for read and write access at the same time on different streams

Code examples

The following code example fails the check and will give a warning:

#include <stdio.h>

void example(void) {
  FILE *f1 = fopen("foo", "r");
  FILE *f2;
  f2 = fopen("foo", "w");

}

The following code example passes the check and will not give a warning about this issue:

#include <stdio.h>

void example(void) {
  FILE *f1 = fopen("foo", "r");
  FILE *f2;
  fclose(f1);
  f2 = fopen("foo", "r");

}