r226454 - clang-format: Fix crasher on weird comments.

Nico Weber thakis at chromium.org
Mon Jan 19 10:16:14 PST 2015


Nice! Did you run a fuzzer to find all these?

On Mon, Jan 19, 2015 at 3:49 AM, Daniel Jasper <djasper at google.com> wrote:

> Author: djasper
> Date: Mon Jan 19 05:49:32 2015
> New Revision: 226454
>
> URL: http://llvm.org/viewvc/llvm-project?rev=226454&view=rev
> Log:
> clang-format: Fix crasher on weird comments.
>
> Crashing input:
>   /\
>   / comment
>
> Modified:
>     cfe/trunk/lib/Format/TokenAnnotator.cpp
>     cfe/trunk/unittests/Format/FormatTest.cpp
>
> Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=226454&r1=226453&r2=226454&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
> +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jan 19 05:49:32 2015
> @@ -838,10 +838,8 @@ private:
>                 (!Current.Previous ||
> Current.Previous->isNot(tok::l_square))) {
>        Current.Type = TT_BinaryOperator;
>      } else if (Current.is(tok::comment)) {
> -      if (Current.TokenText.startswith("//"))
> -        Current.Type = TT_LineComment;
> -      else
> -        Current.Type = TT_BlockComment;
> +      Current.Type =
> +          Current.TokenText.startswith("/*") ? TT_BlockComment :
> TT_LineComment;
>      } else if (Current.is(tok::r_paren)) {
>        if (rParenEndsCast(Current))
>          Current.Type = TT_CastRParen;
>
> Modified: cfe/trunk/unittests/Format/FormatTest.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=226454&r1=226453&r2=226454&view=diff
>
> ==============================================================================
> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)
> +++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 19 05:49:32 2015
> @@ -1035,6 +1035,9 @@ TEST_F(FormatTest, UnderstandsSingleLine
>                     "     // spanning two lines\n"
>                     " x + 3) {\n"
>                     "}"));
> +
> +  verifyNoCrash("/\\\n/");
> +  verifyNoCrash("/\\\n* */");
>  }
>
>  TEST_F(FormatTest, KeepsParameterWithTrailingCommentsOnTheirOwnLine) {
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150119/b85a93ad/attachment.html>


More information about the cfe-commits mailing list