dwarfdump: Add some error handling for DWP index sections of the wrong size
[oota-llvm.git] / tools / yaml2obj / yaml2obj.cpp
index dd41951e7db8924dd8b928be6409ddd12bccd08e..af4d8689067240d3a65ce3fceb41ad03ddf0fe73 100644 (file)
@@ -62,7 +62,8 @@ static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"),
 
 typedef int (*ConvertFuncPtr)(yaml::Input & YIn, raw_ostream &Out);
 
-int convertYAML(yaml::Input & YIn, raw_ostream &Out, ConvertFuncPtr Convert) {
+static int convertYAML(yaml::Input &YIn, raw_ostream &Out,
+                       ConvertFuncPtr Convert) {
   unsigned CurDocNum = 0;
   do {
     if (++CurDocNum == DocNum)
@@ -83,16 +84,17 @@ int main(int argc, char **argv) {
   if (OutputFilename.empty())
     OutputFilename = "-";
 
-  std::string ErrorInfo;
+  std::error_code EC;
   std::unique_ptr<tool_output_file> Out(
-      new tool_output_file(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None));
-  if (!ErrorInfo.empty()) {
-    errs() << ErrorInfo << '\n';
+      new tool_output_file(OutputFilename, EC, sys::fs::F_None));
+  if (EC) {
+    errs() << EC.message() << '\n';
     return 1;
   }
 
-  std::unique_ptr<MemoryBuffer> Buf;
-  if (MemoryBuffer::getFileOrSTDIN(Input, Buf))
+  ErrorOr<std::unique_ptr<MemoryBuffer>> Buf =
+      MemoryBuffer::getFileOrSTDIN(Input);
+  if (!Buf)
     return 1;
 
   ConvertFuncPtr Convert = nullptr;
@@ -105,7 +107,7 @@ int main(int argc, char **argv) {
     return 1;
   }
 
-  yaml::Input YIn(Buf->getBuffer());
+  yaml::Input YIn(Buf.get()->getBuffer());
 
   int Res = convertYAML(YIn, Out->os(), Convert);
   if (Res == 0)