[PATCH] D102770: [clang-tidy] Fix a crash for raw-string-literal check.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 19 06:38:01 PDT 2021
hokein created this revision.
hokein added a reviewer: gribozavr2.
Herald added a subscriber: xazax.hun.
hokein requested review of this revision.
Herald added a project: clang-tools-extra.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D102770
Files:
clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
Index: clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
@@ -56,7 +56,7 @@
*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)");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102770.346439.patch
Type: text/x-patch
Size: 656 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210519/1a77a7cd/attachment.bin>
More information about the cfe-commits
mailing list