...
This compliant solution uses the identifier assigned to the constant value in the expression.:
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdio.h> /* ... */ nblocks = 1 + (nbytes - 1) / BUFSIZ; |
...
Assuming the value of an expression diminishes the maintainability of code and can produce unexpected behavior under any circumstances in which the constant changes.
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
EXP07-C |
Low |
Unlikely |
Medium | P2 | L3 |
Automated Detection
LDRA tool suite
Section
LDRA
LDRA
PRQA QA-C Include Page PRQA_V PRQA_V 3120
Tool | Version | Checker | Description |
---|
Axivion Bauhaus Suite |
|
|
|
Section |
---|
201 S |
Section |
---|
Fully Implemented |
Partially Implemented
CertC-EXP07 | |||||||||
Helix QAC |
| C3120, C3121, C3122, C3123, C3131, C3132 | |||||||
LDRA tool suite |
| 201 S | Fully implemented |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
SEI CERT C++ |
Coding Standard | VOID EXP07-CPP. Do not diminish the benefits of constants by assuming their values in expressions |
Bibliography
...
[Plum 1985] | Rule 1-5 |
...