According to MISRA 2008, concatenation of wide and narrow string literals leads to undefined behavior. This was once considered implicitly undefined behavior until C90 [ISO/IEC 9899:1990]. However, C99 defined this behavior [ISO/IEC 9899:1999], and C11 further explains in section 6.4.5, paragraph 5 [ISO/IEC 9899:2011]:
...
Nonetheless, it is recommended that string literals that are concatenated should all be the same type so as not to rely on implementation-defined behavior or undefined behavior if compiled on a platform that supports only C90.
...
This noncompliant code example concatenates wide and narrow string literals. Although the behavior is undefined in C90, the programmer probably intended to create a wide - string literal.
Code Block | ||||
---|---|---|---|---|
| ||||
wchar_t *msg = L"This message is very long, so I want to divide it " "into two parts."; |
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
MISRA-C++ | Rule 2-13-5: MISRA.STRINGS.CONCAT Narrow and wide string literals concatenated |
Bibliography
...
...
2011] | Section 6.4.5, "String |
...
Literals" |
...