[llvm] r357219 - [yaml2obj] Fixing opening empty yaml files.

Puyan Lotfi via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 15:55:08 PDT 2019


Author: zer0
Date: Thu Mar 28 15:55:08 2019
New Revision: 357219

URL: http://llvm.org/viewvc/llvm-project?rev=357219&view=rev
Log:
[yaml2obj] Fixing opening empty yaml files.

Essentially echo "" | yaml2obj crashes. This patch attempts to trim whitespace
and determine if the yaml string in the file is empty or not. If the input is
empty then it will not properly print out an error message and return an error
code.

Differential Revision: https://reviews.llvm.org/D59964

A    test/tools/yaml2obj/empty.yaml
M    tools/yaml2obj/yaml2obj.cpp

Added:
    llvm/trunk/test/tools/yaml2obj/empty.yaml
Modified:
    llvm/trunk/tools/yaml2obj/yaml2obj.cpp

Added: llvm/trunk/test/tools/yaml2obj/empty.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/empty.yaml?rev=357219&view=auto
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/empty.yaml (added)
+++ llvm/trunk/test/tools/yaml2obj/empty.yaml Thu Mar 28 15:55:08 2019
@@ -0,0 +1,5 @@
+# RUN: echo "" | not yaml2obj 2>&1 | FileCheck %s
+# RUN: echo -n "" | not yaml2obj 2>&1 | FileCheck %s
+# RUN: echo " " | not yaml2obj 2>&1 | FileCheck %s
+# RUN: echo "  " | not yaml2obj 2>&1 | FileCheck %s
+# CHECK: yaml2obj: Error opening '-': Empty File.

Modified: llvm/trunk/tools/yaml2obj/yaml2obj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2obj.cpp?rev=357219&r1=357218&r2=357219&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2obj.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2obj.cpp Thu Mar 28 15:55:08 2019
@@ -86,7 +86,10 @@ int main(int argc, char **argv) {
   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)




More information about the llvm-commits mailing list