[PATCH] D59964: [yaml2obj] Fixing opening empty yaml files.

Puyan Lotfi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 14:59:08 PDT 2019


plotfi created this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Essentially echo "" | yaml2obj crashes. This patch attempts to trim whitespace and determine if the yaml string in the file is empty or not.


Repository:
  rL LLVM

https://reviews.llvm.org/D59964

Files:
  test/tools/yaml2obj/empty.yaml
  tools/yaml2obj/yaml2obj.cpp


Index: tools/yaml2obj/yaml2obj.cpp
===================================================================
--- tools/yaml2obj/yaml2obj.cpp
+++ tools/yaml2obj/yaml2obj.cpp
@@ -86,7 +86,11 @@
   if (!Buf)
     return 1;
 
-  yaml::Input YIn(Buf.get()->getBuffer());
+  StringRef Buffer = Buf.get()->getBuffer();
+  if (Buffer.trim().size() == 0)
+    error("yaml2obj: Error opening '" + Input + "': Empty File.");
+
+  yaml::Input YIn(Buffer);
 
   int Res = convertYAML(YIn, Out->os());
   if (Res == 0)
Index: test/tools/yaml2obj/empty.yaml
===================================================================
--- /dev/null
+++ test/tools/yaml2obj/empty.yaml
@@ -0,0 +1,4 @@
+# RUN: echo "" | not yaml2obj
+# RUN: echo -n "" | not yaml2obj
+# RUN: echo " " | not yaml2obj
+# RUN: echo "  " | not yaml2obj


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59964.192720.patch
Type: text/x-patch
Size: 800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190328/3bebc5e8/attachment.bin>


More information about the llvm-commits mailing list