[PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

Etienne Bergeron via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 6 07:30:46 PDT 2016


etienneb added a comment.

I finally get rid of the GetCharAt function.


================
Comment at: clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp:22
@@ +21,3 @@
+static unsigned int GetCharAt(const StringLiteral *SL, size_t offset) {
+  if (offset >= SL->getLength()) return 0;
+  return SL->getCodeUnit(offset);
----------------
alexfh wrote:
> Should this be an assert instead?
No, because we are not doing bounds check later:

      if (GetCharAt(SL, i) == 0 &&
          GetCharAt(SL, i + 1) == 'x' &&
          isDigit(GetCharAt(SL, i + 2)) &&
          isDigit(GetCharAt(SL, i + 3))) {

We can move this as an assert, and in this case... we can modify the "if" to check the length.


http://reviews.llvm.org/D18783





More information about the cfe-commits mailing list