Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
bgColor#FFcccc
langc
#define ABS(x) (((x) < 0) ? -(x) : (x))
 
void func(int n) {
  /* validateValidate 'n' is within the desired range */
  int m = ABS(++n);

  /* ... */
}

...

Code Block
bgColor#ccccff
langc
#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
bgColor#ccccff
langc
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
Include Page
ECLAIR_V
ECLAIR_V
CC2.PRE31Fully implemented

LDRA tool suite

Include Page
LDRA_V
LDRA_V

9 S
562 S

Partially implemented

PRQA QA-C
Include Page
PRQA_V
PRQA_V

3454
3455
3456

Fully implemented

...