MISRA C++:2023 Rule 22.4.1
Description
Rule Definition
The literal value zero shall be the only value assigned to
errno
.
Rationale
Several C++ Standard Library functions set errno
to non-zero values to indicate error conditions. To check for errors following a call to one of these functions, you can set errno
to zero before the call and check for nonzero values following the call. For this usage, you only need to set errno
to the literal value zero.
This rule prevents the use of errno
in other contexts. For instance, do not use errno
for error-reporting in a custom library function that you create. C++ provides more superior methods for error-handling in these contexts.
Polyspace Implementation
The rule checker reports a violation if a nonzero value is assigned to the variable errno
defined in the header <cerrno>
.
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: Diagnostics library |
Category: Required |
Version History
Introduced in R2024b