...
The documentation for unsafe macros must warn about putting side effects on the invocation, but the responsibility is on the programmer using the macro. Because of the risks associated with their use, it is recommended that you avoid the creation of unsafe macro functions. (See PRE00-C. Prefer inline or static functions to function-like macros.)
...
Code Block | ||||
---|---|---|---|---|
| ||||
#define ABS(x) (((x) < 0) ? -(x) : (x)) void func(int n) { /* validateValidate 'n' is within the desired range */ int m = ABS(++n); /* ... */ } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#define ABS(x) (((x) < 0) ? -(x) : (x)) /* UNSAFE */ void func(int n) { /* validateValidate 'n' is within the desired range */ ++n; int m = ABS(n); /* ... */ } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
inline int abs(int x) { return (((x) < 0) ? -(x) : (x)); } void func(int n) { /* validateValidate 'n' is within the desired range */ int m = abs(++n); /* ... */ } |
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
PRE31-C | lowLow | unlikelyUnlikely | lowLow | P3 | L3 |
Automated Detection
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
ECLAIR |
| CC2.PRE31 | Fully implemented | ||||||
| 9 S | Partially implemented | |||||||
PRQA QA-C |
| 3454 | Fully implemented |
...