]> granicus.if.org Git - llvm/commitdiff
[yaml2obj] - Don't crash on invalid document.
authorGeorge Rimar <grimar@accesssoftek.com>
Wed, 20 Sep 2017 09:57:11 +0000 (09:57 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Wed, 20 Sep 2017 09:57:11 +0000 (09:57 +0000)
Previously jaml2obj would segfault on empty document.
(without yaml description).
Patch fixes the issue.

Differential revision: https://reviews.llvm.org/D38036

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

include/llvm/Support/YAMLTraits.h
test/Object/yaml2obj-invalid.yaml [new file with mode: 0644]

index 71fdf47f1979a3095b83e2a3e0197178474b8263..5f6f0493e28b485f9e35848561b60273e98cf7a1 100644 (file)
@@ -1418,8 +1418,8 @@ inline typename std::enable_if<has_MappingTraits<T, EmptyContext>::value,
                                Input &>::type
 operator>>(Input &yin, T &docMap) {
   EmptyContext Ctx;
-  yin.setCurrentDocument();
-  yamlize(yin, docMap, true, Ctx);
+  if (yin.setCurrentDocument())
+    yamlize(yin, docMap, true, Ctx);
   return yin;
 }
 
diff --git a/test/Object/yaml2obj-invalid.yaml b/test/Object/yaml2obj-invalid.yaml
new file mode 100644 (file)
index 0000000..d1f4fa2
--- /dev/null
@@ -0,0 +1,2 @@
+# RUN: not yaml2obj %s 2>&1 | FileCheck %s
+# CHECK: Unknown document type!