...
The C Standard [ISO/IEC 9899:2011] identifies the following undefined behavior:
A restrict-qualified pointer is assigned a value based on another restricted pointer whose associated block neither began execution before the block associated with this pointer, nor ended before the assignment (6.7.3.1).
...
The function g()
declares an array d
consisting of 100 int
values and then invokes f()
to copy memory from one area of the array to another. This call has undefined behavior because each of d[1]
through d[49]
is accessed through both p
and q
.
...
In this compliant solution, the function f()
is unchanged but the programmer has ensured that none of the calls to f()
result in undefined behavior. The call to f()
in g()
is valid because the storage allocated to d
is effectively divided into two disjoint objects.
...
Ensure that restrict
-qualified source and destination pointers do not reference overlapping objects when invoking library functions. For example, the following table lists C Standard standard library functions that copy memory from a source object referenced by a restrict
-qualified pointer to a destination object that is also referenced by a restrict
-qualified pointer:
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
EXP43-C | Medium | Probable | High | P4 | L3 |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
| 480 S, 489 S, 613 S | Enhanced Enforcementenforcement | |||||||
PRQA QA-C |
| 3314 | |||||||
SonarQube Plugin |
| S1836 | Implements MISRA C:2012 Rule 8.14 |
...
- MISRA Rule 8.14 prohibits the use of the restrict keyword except in C Standard Library Functionsstandard library functions.
Bibliography
[ISO/IEC 9899:2011] | 6.7.3.1, "Formal Definition of restrict " |
[Walls 2006] |
...