[clang-doc] Fix segfault in comment sorting
authorJulie Hockett <juliehockett@google.com>
Tue, 2 Jul 2019 17:57:11 +0000 (17:57 +0000)
committerJulie Hockett <juliehockett@google.com>
Tue, 2 Jul 2019 17:57:11 +0000 (17:57 +0000)
Differential Revision: https://reviews.llvm.org/D63962

llvm-svn: 364949

clang-tools-extra/clang-doc/Representation.h

index c1f3fd4..a142bba 100644 (file)
@@ -75,15 +75,16 @@ struct CommentInfo {
                  Other.ParamName, Other.CloseName, Other.SelfClosing,
                  Other.Explicit, Other.AttrKeys, Other.AttrValues, Other.Args);
 
-    if (FirstCI < SecondCI ||
-        (FirstCI == SecondCI && Children.size() < Other.Children.size()))
+    if (FirstCI < SecondCI)
       return true;
 
-    if (FirstCI > SecondCI || Children.size() > Other.Children.size())
-      return false;
+    if (FirstCI == SecondCI) {
+      return std::lexicographical_compare(
+          Children.begin(), Children.end(), Other.Children.begin(),
+          Other.Children.end(), llvm::deref<llvm::less>());
+    }
 
-    return std::equal(Children.begin(), Children.end(), Other.Children.begin(),
-                      llvm::deref<llvm::less>{});
+    return false;
   }
 
   SmallString<16>