Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V2600. MISRA. The standard...
menu mobile close menu
Additional information
toggle menu Contents

V2600. MISRA. The standard input/output functions should not be used.

Jul 20 2021

This diagnostic rule is based on the MISRA (Motor Industry Software Reliability Association) manual for software development.

The standard library functions from the '<stdio.h>' / '<cstdio>' and '<wchar.h>' header files can be dangerous. Their behavior depends on the implementation. Besides, their use may lead to undefined behavior.

Look at the code fragment:

#include <stdio.h>

void InputFromFile(FILE *file); // Read from 'file'

void foo()
{
  FILE *stream;
  ....
  InputFromFile(stream);
  fflush(stream);
}

First, the code reads data via the 'stream' file descriptor, which is then passed to the 'fflush' function. This sequence of operations leads to undefined behavior.

The analyzer issues a warning if it detects the use of any functions defined in the '<stdio.h>' / '<cstdio>' and '<wchar.h>' header files:

  • fopen;
  • fclose;
  • freopen;
  • fflush;
  • setbuf;
  • setvbuf;
  • etc.

For example, the analyzer issues a warning for the code below:

#include <stdio.h>

void foo(const char *filename, FILE *oldFd)
{
  FILE *newFd = freopen(filename, "r", oldFd);
  ....
}

This diagnostic is classified as:

  • CWE-676
  • MISRA-C-2012-21.6
  • MISRA-C-2023-21.6
  • MISRA-CPP-2008-27.0.1