[PATCH] D56442: [clangd] Fix a crash when reading an empty index file.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 8 07:28:42 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL350633: [clangd] Fix a crash when reading an empty index file. (authored by hokein, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56442/new/

https://reviews.llvm.org/D56442

Files:
  clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp
  clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp


Index: clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp
===================================================================
--- clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp
@@ -91,6 +91,10 @@
   return (arg.IncludeHeader == IncludeHeader) && (arg.References == References);
 }
 
+TEST(SerializationTest, NoCrashOnEmptyYAML) {
+  EXPECT_TRUE(bool(readIndexFile("")));
+}
+
 TEST(SerializationTest, YAMLConversions) {
   auto In = readIndexFile(YAML);
   EXPECT_TRUE(bool(In)) << In.takeError();
Index: clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp
+++ clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp
@@ -314,17 +314,20 @@
       Arena; // store the underlying data of Position::FileURI.
   llvm::UniqueStringSaver Strings(Arena);
   llvm::yaml::Input Yin(Data, &Strings);
-  do {
+  while (Yin.setCurrentDocument()) {
+    llvm::yaml::EmptyContext Ctx;
     VariantEntry Variant;
-    Yin >> Variant;
+    yamlize(Yin, Variant, true, Ctx);
     if (Yin.error())
       return llvm::errorCodeToError(Yin.error());
+
     if (Variant.Symbol)
       Symbols.insert(*Variant.Symbol);
     if (Variant.Refs)
       for (const auto &Ref : Variant.Refs->second)
         Refs.insert(Variant.Refs->first, Ref);
-  } while (Yin.nextDocument());
+    Yin.nextDocument();
+  }
 
   IndexFileIn Result;
   Result.Symbols.emplace(std::move(Symbols).build());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56442.180671.patch
Type: text/x-patch
Size: 1602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190108/8e9e6ccf/attachment.bin>


More information about the cfe-commits mailing list