Versions Compared

Key

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

...

This compliant solution addresses the const violation by not modifying the constant argument.:

Code Block
bgColor#ccccff
langc
void foo(const int * x) {
  if (x != NULL) {
    printf("Value is %d\n", *x);
  }
  /* ... */
}

...

In the first strcat_nc() call, the compiler generates a warning about attempting to cast away const on str2. This is because strcat_nc() does not modify its second argument , yet fails to declare it const.

...

In the final strcat_nc() call, the compiler generates a warning about attempting to cast away const on str4. This , which is a valid warning.

Compliant Solution

...

Tool

Version

Checker

Description

Compass/ROSE

 

 

Can detect violations of this recommendation while checking for violations of recommendation DCL00-C. Const-qualify immutable objects.

ECLAIR

Include Page
ECLAIR_V
ECLAIR_V

cnstpnte

Fully implemented.

LDRA tool suite

Include Page
LDRA_V
LDRA_V

62 D

Fully implemented.

PRQA QA-C
Include Page
PRQA_V
PRQA_V

3673
0431(C)

Fully implemented.

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

...