]> granicus.if.org Git - clang/commitdiff
Fix clang-format segfault.
authorDaniel Jasper <djasper@google.com>
Mon, 18 Mar 2013 12:50:26 +0000 (12:50 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 18 Mar 2013 12:50:26 +0000 (12:50 +0000)
When annotating "lines" starting with ":", clang-format would segfault.
This could actually happen in valid code, e.g.
  #define A :

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177283 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 8267a25d031fbd32a304874d22d9857edc9ebfb3..4ac4c9b1b85a9e959e2216deaf86726f434da1ea 100644 (file)
@@ -319,6 +319,8 @@ private:
         Tok->Type = TT_ObjCMethodSpecifier;
       break;
     case tok::colon:
+      if (Tok->Parent == NULL)
+        return false;
       // Colons from ?: are handled in parseConditional().
       if (Tok->Parent->is(tok::r_paren) && Contexts.size() == 1) {
         Tok->Type = TT_CtorInitializerColon;
index 4ac9bce56be61312163549643af037fe7f23769e..e6ae81da5c81d8d5d6d8890ff69d2663be402a2c 100644 (file)
@@ -1068,6 +1068,8 @@ TEST_F(FormatTest, EmptyLinesInMacroDefinitions) {
 }
 
 TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) {
+  verifyFormat("#define A :");
+
   // FIXME: Improve formatting of case labels in macros.
   verifyFormat("#define SOMECASES  \\\n"
                "case 1:            \\\n"