<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 29, 2015 at 5:22 PM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@gmail.com" target="_blank">benny.kra@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Tue, Dec 29, 2015 at 5:14 PM, Alexander Kornienko via cfe-commits<br>
<<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
> Author: alexfh<br>
> Date: Tue Dec 29 10:14:38 2015<br>
> New Revision: 256562<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=256562&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=256562&view=rev</a><br>
> Log:<br>
> [clang-tidy] Fix a use-after-free bug found by asan<br>
><br>
> Modified:<br>
>     clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp<br>
><br>
> Modified: clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp?rev=256562&r1=256561&r2=256562&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp?rev=256562&r1=256561&r2=256562&view=diff</a><br>
> ==============================================================================<br>
> --- clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp (original)<br>
> +++ clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp Tue Dec 29 10:14:38 2015<br>
> @@ -491,9 +491,10 @@ void SimplifyBooleanExprCheck::check(con<br>
>  bool containsDiscardedTokens(<br>
>      const ast_matchers::MatchFinder::MatchResult &Result,<br>
>      CharSourceRange CharRange) {<br>
> -  StringRef ReplacementText =<br>
> +  std::string ReplacementText =<br>
>        Lexer::getSourceText(CharRange, *Result.SourceManager,<br>
> -                           Result.Context->getLangOpts()).str();<br>
> +                           Result.Context->getLangOpts())<br>
> +          .str();<br>
<br>
</div></div>Can you just drop the .str() and change the type back to StringRef?<br></blockquote><div><br></div><div>That was what I asked the author of the original patch. However, Lexer expects the buffer to end with a '\0', so the author did only a half of my suggestion and I skipped the issue ;)</div><div><br></div><div>An alternative solution would be to create a lexer from the whole buffer, but then the code would be much more complicated for no reason. Keep in mind that we only do this when we're generating a warning anyway, so copying a string is not going to be a bottleneck.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
- Ben<br>
<div class="HOEnZb"><div class="h5"><br>
>    Lexer Lex(CharRange.getBegin(), Result.Context->getLangOpts(),<br>
>              ReplacementText.data(), ReplacementText.data(),<br>
>              ReplacementText.data() + ReplacementText.size());<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div></div>