MISRA C++:2023 Rule 30.0.1
Description
Rule Definition
The C Library input/output functions shall not be used. 1
Rationale
Functions in <cstdio> such as gets(),
fgetpos(), fopen(), ftell(), etc.
have unspecified, undefined and implementation-defined behavior.
For instance:
The
gets()function has this use case:The function does not check if the number of characters provided at the standard input exceeds the bufferchar * gets ( char * buf );
buf. The function can have unexpected behavior when the input exceeds the buffer. Do not use the wide-character function equivalents in<cwchar>.The
fopenfunction has implementation-specific behavior related to whether it setserrnoon errors or whether it accepts additional characters following the standard mode specifiers.
Polyspace Implementation
Polyspace® reports a violation of this rule if you use the functions declared in
<cstdio> or the wide-character equivalents in
<cwchar>. Polyspace detects the use of these <cstdio> functions:
File operation functions such as
remove()andrename().File access functions such as
fclose(),fflush(), andfopen().Formatted input/output functions such as
fprintf(),fscanf(),printf(), andscanf().Character input output functions such as
fgetc(),fgets(),fputc(), andgetc().Direct input/output functions such as
fread()andfwrite().File positioning functions such as
fgetpos()andfsetpos().Error handling functions such as
clearerr(),ferror(), andperror().
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
| Group: Input/Output Library |
| Category: Required |
Version History
Introduced in R2024b
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.