[clang-tools-extra] 775ca3a - [clang-tidy] Fix a crash for raw-string-literal check.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu May 20 00:17:06 PDT 2021


Author: Haojian Wu
Date: 2021-05-20T09:16:43+02:00
New Revision: 775ca3a89cba104d7c0dc762a0c5c5624c1d397c

URL: https://github.com/llvm/llvm-project/commit/775ca3a89cba104d7c0dc762a0c5c5624c1d397c
DIFF: https://github.com/llvm/llvm-project/commit/775ca3a89cba104d7c0dc762a0c5c5624c1d397c.diff

LOG: [clang-tidy] Fix a crash for raw-string-literal check.

getSourceText could return an empty string for error cases (e.g. invalid
source locaiton), this patch makes the code more robust.

The crash did happen in our internal codebase, but unfortunately I
didn't manage to get a reproduce case. One thing I can confirm from
the core dump is that the crash is caused by calling isRawStringLiteral
on an empty Text.

Differential Revision: https://reviews.llvm.org/D102770

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp b/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
index 7990bc2b8f2a6..26b1d8ecdc319 100644
--- a/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
@@ -56,7 +56,7 @@ bool containsEscapedCharacters(const MatchFinder::MatchResult &Result,
       *Result.SourceManager, Result.Context->getLangOpts());
   StringRef Text = Lexer::getSourceText(CharRange, *Result.SourceManager,
                                         Result.Context->getLangOpts());
-  if (isRawStringLiteral(Text))
+  if (Text.empty() || isRawStringLiteral(Text))
     return false;
 
   return containsEscapes(Text, R"('\"?x01)");


        


More information about the cfe-commits mailing list