From: Daniel Jasper Date: Mon, 19 Jan 2015 10:51:42 +0000 (+0000) Subject: clang-format: Fix crash on invalid code. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=733b278f48ae0d9bf7251ce7f5b8375ef9f10c86;p=clang clang-format: Fix crash on invalid code. Input "a<," made clang-format crash. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226450 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/FormatToken.cpp b/lib/Format/FormatToken.cpp index badb3a39c8..0addbfed0c 100644 --- a/lib/Format/FormatToken.cpp +++ b/lib/Format/FormatToken.cpp @@ -59,7 +59,8 @@ void TokenRole::precomputeFormattingInfos(const FormatToken *Token) {} unsigned CommaSeparatedList::formatAfterToken(LineState &State, ContinuationIndenter *Indenter, bool DryRun) { - if (!State.NextToken->Previous || !State.NextToken->Previous->Previous) + if (State.NextToken == nullptr || !State.NextToken->Previous || + !State.NextToken->Previous->Previous) return 0; // Ensure that we start on the opening brace. diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 1352615814..548273ade0 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -6038,6 +6038,8 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) { // No column layout should be used here. verifyFormat("aaaaaaaaaaaaaaa = {aaaaaaaaaaaaaaaaaaaaaaaaaaa, 0, 0,\n" " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb};"); + + verifyNoCrash("a<,"); } TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {