[PATCH] D38036: [yaml2obj] - Don't crash on invalid document.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 22 04:26:36 PDT 2017
grimar updated this revision to Diff 116329.
grimar added a comment.
- Addressed review comment.
https://reviews.llvm.org/D38036
Files:
lib/ObjectYAML/ObjectYAML.cpp
lib/Support/YAMLParser.cpp
lib/Support/YAMLTraits.cpp
test/Object/yaml2obj-invalid2.yaml
Index: test/Object/yaml2obj-invalid2.yaml
===================================================================
--- test/Object/yaml2obj-invalid2.yaml
+++ test/Object/yaml2obj-invalid2.yaml
@@ -0,0 +1,2 @@
+# RUN: not yaml2obj %s 2>&1 | FileCheck %s
+# CHECK: <unknown>:0: error: YAML Object File missing document type tag!
Index: lib/Support/YAMLTraits.cpp
===================================================================
--- lib/Support/YAMLTraits.cpp
+++ lib/Support/YAMLTraits.cpp
@@ -113,6 +113,8 @@
}
bool Input::mapTag(StringRef Tag, bool Default) {
+ 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.
@@ -340,8 +342,7 @@
void Input::blockScalarString(StringRef &S) { scalarString(S, false); }
void Input::setError(HNode *hnode, const Twine &message) {
- assert(hnode && "HNode must not be NULL");
- this->setError(hnode->_node, message);
+ this->setError(hnode ? hnode->_node : (Node *)nullptr, message);
}
void Input::setError(Node *node, const Twine &message) {
Index: lib/Support/YAMLParser.cpp
===================================================================
--- lib/Support/YAMLParser.cpp
+++ lib/Support/YAMLParser.cpp
@@ -1769,10 +1769,8 @@
bool Stream::failed() { return scanner->failed(); }
void Stream::printError(Node *N, const Twine &Msg) {
- scanner->printError( N->getSourceRange().Start
- , SourceMgr::DK_Error
- , Msg
- , N->getSourceRange());
+ scanner->printError(N ? N->getSourceRange().Start : SMLoc(),
+ SourceMgr::DK_Error, Msg, N ? N->getSourceRange() : None);
}
document_iterator Stream::begin() {
Index: lib/ObjectYAML/ObjectYAML.cpp
===================================================================
--- lib/ObjectYAML/ObjectYAML.cpp
+++ lib/ObjectYAML/ObjectYAML.cpp
@@ -51,7 +51,9 @@
MappingTraits<WasmYAML::Object>::mapping(IO, *ObjectFile.Wasm);
} else {
Input &In = (Input &)IO;
- std::string Tag = In.getCurrentNode()->getRawTag();
+ std::string Tag;
+ if (In.getCurrentNode())
+ Tag = In.getCurrentNode()->getRawTag();
if (Tag.empty())
IO.setError("YAML Object File missing document type tag!");
else
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38036.116329.patch
Type: text/x-patch
Size: 2364 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170922/7037c4cd/attachment.bin>
More information about the llvm-commits
mailing list