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)"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits