MISRA C:2012 Rule 7.4
A string literal shall not be assigned to an object unless the object’s type is “pointer to const-qualified char”
Description
Rule Definition
A string literal shall not be assigned to an object unless the object’s type is “pointer to const-qualified char”.
Rationale
This rule prevents assignments that allow modification of a string literal.
An attempt to modify a string literal can result in undefined behavior. For example, some implementations can store string literals in read-only memory. An attempt to modify the string literal can result in an exception or crash.
As an exception, passing a string literal to a variadic function through a variable argument list does not violate this rule.
Polyspace Implementation
The rule checker flags assignment of string literals to:
Pointers with data type other than
const char*
.Arrays with data type other than
const char
.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Literals and Constants |
Category: Required |
AGC Category: Required |
Version History
Introduced in R2014b