Versions Compared

Key

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

...

At compile time, string literals are used to create an array of static storage duration of sufficient length to contain the character sequence and a terminating null character. It is unspecified whether these arrays of string literals are distinct from each other. The behavior is undefined if a program attempts to modify any string literals. Modifying a string literal frequently results in an access violation because string literals are typically stored in read-only memory. See also undefined behavior 33  of Annex J of the C Standard [ISO/IEC 9899:2011].

String literals are usually referred to via a pointer to, or array of, const characters.

...

This rule is an instance of EXP40-C. Do not modify constant valuesobjects.

Noncompliant Code Example

...

This compliant solution avoids modifying a const object, even if it is possible to obtain a non-const pointer to such an object by calling a standard C library function, such as strrchr(). To reduce the risk of callers of get_dirname(), a buffer and length for the directory name are passed into the function.   It is insufficient to change pathname to require a char * instead of a const char * because conforming compilers are not required to diagnose passing a string literal to a function accepting a char *.

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

STR30-C

lowLow

likelyLikely

lowLow

P9

L2

Automated Detection

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
 

 

...