Details

    • Message:
      Remove all trigraph sequences: ??=, ??/, ??', ??(, ??), ??!, ??<, ??>, ??-.
    • Default Severity:
      Blocker
    • Impact:
      High
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Legacy Key:
      TrigraphUsage
    • Covered Languages:
      C, C++, Objective-C
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      15min
    • CERT:
      PRE07-C.
    • MISRA C 2004:
      4.2
    • MISRA C 2012:
      4.2
    • MISRA C++ 2008:
      2-3-1
    • PC-Lint:
      584, 1584, 585, 1585, 739, 1739

      Description

      Trigraphs are denoted by a sequence of 2 question marks followed by a specified third character (e.g. ??- represents a '~' (tilde) character and ??) represents a ']'). They can cause accidental confusion with other uses of two question marks.

      Noncompliant Code Example

      static const char str[] = "(Date should be in the form ??-??-??)"; // Noncompliant. Evaluates to "(Date should be in the form ~~]"
      

      Compliant Solution

      static const char str[] = "(Date should be in the form ?" "?-?" "?-?" ?)";  // adjacent string literals concatenated at compile time
      static const char str2[] = "(Date should be in the form ?-?-?)"; // problem avoided by eliminating 2nd '?' in each sequence
      static const char str3[] = "(Date should be in the form ? ?-? ?-? ?)"; // problem avoided by spacing '?'s out
      

      See

      • MISRA C:2004, 4.2 - Trigraphs shall not be used
      • MISRA C++:2008, 2-3-1 - Trigraphs shall not be used
      • MISRA C:2012, 4.2 - Trigraphs shall not be used
      • CERT, PRE07-C. - Avoid using repeated question marks

        Attachments

          Issue Links

          1.
          C-Family RSPEC-4389 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: