forked from OSchip/llvm-project
[tools][llvm-lipo] Fix off-by-one error in command-line argument parsing
makeArrayRef(argv + 1, argc) -> makeArrayRef(argv + 1, argc - 1) The previous behavior resulted in propagation of the null pointer into later stages of arguments parsing instead of being automatically handled by the existing check of MissingArgumentCount. Test plan: ninja check-all Differential revision: https://reviews.llvm.org/D132418
This commit is contained in:
parent
8856137ce7
commit
dde23bf98e
|
@ -3,7 +3,7 @@
|
|||
# RUN: yaml2obj %p/Inputs/i386-x86_64-universal.yaml -o %t-universal.o
|
||||
|
||||
# RUN: not llvm-lipo %t-universal.o -replace %t-32.o 2>&1 | FileCheck --check-prefix=MISSING_ARG %s
|
||||
# MISSING_ARG: error: replace is missing an argument: expects -replace arch_type file_name
|
||||
# MISSING_ARG: error: missing argument to -replace option
|
||||
|
||||
# RUN: not llvm-lipo %t-universal.o -replace i386 %t-32.o 2>&1 | FileCheck --check-prefix=OUTPUT_FILE %s
|
||||
# OUTPUT_FILE: error: replace expects a single output file to be specified
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# RUN: yaml2obj %p/Inputs/armv7-slice.yaml -o %t-armv7.o
|
||||
|
||||
# RUN: not llvm-lipo %t-armv7.o %t-arm64.o -create -o %t.o -segalign a 2>&1 | FileCheck --check-prefix=MISSING_ARG %s
|
||||
# MISSING_ARG: error: segalign is missing an argument: expects -segalign arch_type alignment_value
|
||||
# MISSING_ARG: error: missing argument to -segalign option
|
||||
|
||||
# RUN: not llvm-lipo %t-armv7.o %t-arm64.o -o %t.o -segalign arm64 10 2>&1 | FileCheck --check-prefix=MISSING_ACTION %s
|
||||
# MISSING_ACTION: error: at least one action should be specified
|
||||
|
|
|
@ -183,9 +183,7 @@ static Config parseLipoOptions(ArrayRef<const char *> ArgsArr) {
|
|||
C.InputFiles.push_back({None, Arg->getValue()});
|
||||
for (auto Arg : InputArgs.filtered(LIPO_arch)) {
|
||||
validateArchitectureName(Arg->getValue(0));
|
||||
if (!Arg->getValue(1))
|
||||
reportError(
|
||||
"arch is missing an argument: expects -arch arch_type file_name");
|
||||
assert(Arg->getValue(1) && "file_name is missing");
|
||||
C.InputFiles.push_back({StringRef(Arg->getValue(0)), Arg->getValue(1)});
|
||||
}
|
||||
|
||||
|
@ -294,10 +292,7 @@ static Config parseLipoOptions(ArrayRef<const char *> ArgsArr) {
|
|||
|
||||
case LIPO_replace:
|
||||
for (auto Action : ActionArgs) {
|
||||
if (!Action->getValue(1))
|
||||
reportError(
|
||||
"replace is missing an argument: expects -replace arch_type "
|
||||
"file_name");
|
||||
assert(Action->getValue(1) && "file_name is missing");
|
||||
validateArchitectureName(Action->getValue(0));
|
||||
C.ReplacementFiles.push_back(
|
||||
{StringRef(Action->getValue(0)), Action->getValue(1)});
|
||||
|
@ -725,7 +720,7 @@ replaceSlices(LLVMContext &LLVMCtx,
|
|||
|
||||
int main(int argc, char **argv) {
|
||||
InitLLVM X(argc, argv);
|
||||
Config C = parseLipoOptions(makeArrayRef(argv + 1, argc));
|
||||
Config C = parseLipoOptions(makeArrayRef(argv + 1, argc - 1));
|
||||
LLVMContext LLVMCtx;
|
||||
SmallVector<OwningBinary<Binary>, 1> InputBinaries =
|
||||
readInputBinaries(LLVMCtx, C.InputFiles);
|
||||
|
|
Loading…
Reference in New Issue