Versions Compared

Key

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

...

All occurrences in a source file of the following sequences of three characters (that is, trigraph sequences) are replaced with the corresponding single character.

??=

#

 

??)

]

 

??!

|

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="83f764512ff75945-e9b31a8d-40364bec-9d9684af-9b0814e2182a45303699e43b"><ac:plain-text-body><![CDATA[

??(

[

 

??'

^

 

??>

}

]]></ac:plain-text-body></ac:structured-macro>

??/

\

 

??<

{

 

??-

~

...

In this noncompliant code example, a++ is not executed , because the trigraph sequence ??/ is replaced by \, logically putting a++ on the same line as the comment.

...

This compliant solution uses string concatenation to concatenate the two question marks; otherwise, they are interpreted as beginning a trigraph sequence.

...

Inadvertent trigraphs can result in unexpected behavior. Some compilers provide options to warn when trigraphs are encountered or to disable trigraph expansion. Use the warning options and ensure your code compiles cleanly. (See guideline recommendation MSC00-C. Compile cleanly at high warning levels.)

...

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Related Guidelines

CERT C++ Secure Coding Standard: PRE07-CPP. Avoid using repeated question marks

...

Wiki Markup\[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Section 5.2.1.1, "Trigraph sequences" \[[

MISRA 2004|AA. Bibliography#MISRA 04]\] Rule 4.2

Bibliography

...

PRE06-C. Enclose header files in an inclusion guard      01. Preprocessor (PRE)