diff options
Diffstat (limited to 'clang-tools-extra/docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst')
-rw-r--r-- | clang-tools-extra/docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst b/clang-tools-extra/docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst index 3661218acef..8abbfd9b570 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst @@ -6,32 +6,30 @@ misc-string-literal-with-embedded-nul Finds occurences of string literal with embedded NUL character and validates their usage. - Invalid escaping -^^^^^^^^^^^^^^^^ +---------------- Special characters can be escaped within a string literal by using their hexadecimal encoding like ``\x42``. A common mistake is to escape them like this ``\0x42`` where the ``\0`` stands for the NUL character. -.. code:: c++ +.. code-block:: c++ const char* Example[] = "Invalid character: \0x12 should be \x12"; const char* Bytes[] = "\x03\0x02\0x01\0x00\0xFF\0xFF\0xFF"; - Truncated literal -^^^^^^^^^^^^^^^^^ +----------------- -String-like classes can manipulate strings with embedded NUL as they are -keeping track of the bytes and the length. This is not the case for a -``char*`` (NUL-terminated) string. +String-like classes can manipulate strings with embedded NUL as they are keeping +track of the bytes and the length. This is not the case for a ``char*`` +(NUL-terminated) string. A common mistake is to pass a string-literal with embedded NUL to a string constructor expecting a NUL-terminated string. The bytes after the first NUL character are truncated. -.. code:: c++ +.. code-block:: c++ std::string str("abc\0def"); // "def" is truncated str += "\0"; // This statement is doing nothing |