llvm.org GIT mirror llvm / a66a0bf
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357219 91177308-0d34-0410-b5e6-96231b3b80d8 Puyan Lotfi 6 months ago
2 changed file(s) with 9 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
0 # RUN: echo "" | not yaml2obj 2>&1 | FileCheck %s
1 # RUN: echo -n "" | not yaml2obj 2>&1 | FileCheck %s
2 # RUN: echo " " | not yaml2obj 2>&1 | FileCheck %s
3 # RUN: echo " " | not yaml2obj 2>&1 | FileCheck %s
4 # CHECK: yaml2obj: Error opening '-': Empty File.
8585 if (!Buf)
8686 return 1;
8787
88 yaml::Input YIn(Buf.get()->getBuffer());
88 StringRef Buffer = Buf.get()->getBuffer();
89 if (Buffer.trim().size() == 0)
90 error("yaml2obj: Error opening '" + Input + "': Empty File.");
91 yaml::Input YIn(Buffer);
8992
9093 int Res = convertYAML(YIn, Out->os());
9194 if (Res == 0)