MISRA C++:2023 Dir 0.3.2
Description
Directive Definition
A function call shall not violate the function's preconditions.
Rationale
Violating a function's preconditions can result in unexpected behavior.
For instance, the strncpy()
function copies characters from a source to a destination array. The function expects the destination array to have enough memory for the copied characters. If this expectation is violated, you might see unexpected results.
Polyspace Implementation
The rule checker reports violations if the arguments to Standard Library functions do not satisfy the function preconditions. The checker supports these Standard Library functions:
Functions with floating point arguments such as:
Rounding and absolute value functions (
ceil()
,fabs()
,floor()
, and so on)Division and remainder functions (
fmod()
,modf()
Functions involving exponents and logarithms (
frexp()
,ldexp()
,sqrt()
,pow()
,exp()
,log()
,log10()
, and so on)Trigonometric functions (
cos()
,sin()
,tan()
,acos()
,asin()
,atan()
,atan2()
, and so on)
Functions with integer arguments such as:
Integer division functions (
div()
,ldiv()
, and so on)Absolute value functions (
abs()
,labs()
, and so on)
Functions with character arguments such as:
Character conversion functions (
toupper()
,tolower()
, and so on)Character check functions (
isalnum()
,isalpha()
,iscntrl()
,isdigit
, and so on)
Memory-related routines such as
memcpy
String-related routines, such as
strcpy
andstrncpy
.
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: Language Independent Issues |
Category: Required |
Version History
Introduced in R2024b