[yaml2obj] - Don't crash on invalid inputs.
yaml2obj might crash on invalid input when unable to parse the YAML.
Recently a crash with a very similar nature was fixed for an empty files.
This patch revisits the fix and does it in yaml::Input instead.
It seems to be more correct way to handle such situation.
With that crash for invalid inputs is also fixed now.
Differential revision: https://reviews.llvm.org/D61059
llvm-svn: 359178
diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp
index e7932fe..183da5b 100644
--- a/llvm/lib/Support/YAMLTraits.cpp
+++ b/llvm/lib/Support/YAMLTraits.cpp
@@ -113,6 +113,11 @@
}
bool Input::mapTag(StringRef Tag, bool Default) {
+ // CurrentNode can be null if setCurrentDocument() was unable to
+ // parse the document because it was invalid or empty.
+ if (!CurrentNode)
+ return false;
+
std::string foundTag = CurrentNode->_node->getVerbatimTag();
if (foundTag.empty()) {
// If no tag found and 'Tag' is the default, say it was found.