Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-817

Narrow and wide string literals should not be concatenated

    Details

    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Legacy Key:
      NarrowAndWideStringConcat
    • Covered Languages:
      C, C++, Objective-C
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      15min
    • CERT:
      STR10-C.
    • MISRA C++ 2008:
      2-13-5
    • PC-Lint:
      707, 1707

      Description

      Concatenation of wide and narrow string literals leads to undefined behavior.

      Noncompliant Code Example

      wchar_t n_array[] = "Hello" L"World";     // Noncompliant
      wchar_t w_array[] = L"Hello" "World";     // Noncompliant
      

      Compliant Solution

      char_t n_array[] = "Hello" "World";     // Compliant
      wchar_t w_array[] = L"Hello" L"World";	// Compliant
      

      See

      • MISRA C++:2008, 2-13-5 - Narrow and wide string literals shall not be concatenated.
      • CERT STR10-C. - Do not concatenate different type of string literals

        Attachments

          Issue Links

          1.
          C-Family RSPEC-4386 Language-Specification Active Unassigned

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                Anonymous
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated: