Versions Compared

Key

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

...

In this noncompliant code example, the char pointer p is initialized to the address of a string literal. Attempting to modify the string literal results in undefined behavior.:

Code Block
bgColor#FFcccc
langc
char *p  = "string literal";
p[0] = 'S';

...

In this noncompliant code example, a string literal is passed to the (pointer to non-const) parameter of the POSIX function mkstemp(), which then modifies the characters of the string literal.:

Code Block
bgColor#FFcccc
langc
char *fname;
fname = mkstemp("/tmp/edXXXXXX");

...

Tool

Version

Checker

Description

Compass/ROSE

  

Can detect simple violations of this rule.

LDRA tool suite

Include Page
LDRA_V
LDRA_V

157 S

Partially implemented.
PRQA QA-C
Include Page
PRQA_V
PRQA_V
0556Partially implemented.

Splint

Include Page
Splint_V
Splint_V
 

 

...

Bibliography

[Plum 1991]Topic 1.26, "Strings—String Literals"
[Summit 1995]comp.lang.c FAQ list, Question 1.32[Plum 1991]Topic 1.26, "Strings—String Literals"

 

...