diff options
-rw-r--r-- | llvm/test/tools/yaml2obj/empty.yaml | 5 | ||||
-rw-r--r-- | llvm/tools/yaml2obj/yaml2obj.cpp | 5 |
2 files changed, 9 insertions, 1 deletions
diff --git a/llvm/test/tools/yaml2obj/empty.yaml b/llvm/test/tools/yaml2obj/empty.yaml new file mode 100644 index 00000000000..2debd187df2 --- /dev/null +++ b/llvm/test/tools/yaml2obj/empty.yaml @@ -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. diff --git a/llvm/tools/yaml2obj/yaml2obj.cpp b/llvm/tools/yaml2obj/yaml2obj.cpp index 58e69fd5a5b..ef35458a8f0 100644 --- a/llvm/tools/yaml2obj/yaml2obj.cpp +++ b/llvm/tools/yaml2obj/yaml2obj.cpp @@ -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) |