[llvm] dde23bf - [tools][llvm-lipo] Fix off-by-one error in command-line argument parsing
Alexander Shaposhnikov via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 23 12:52:43 PDT 2022
Author: Alexander Shaposhnikov
Date: 2022-08-23T19:48:11Z
New Revision: dde23bf98ecb309dd36405cff7270c613834a534
URL: https://github.com/llvm/llvm-project/commit/dde23bf98ecb309dd36405cff7270c613834a534
DIFF: https://github.com/llvm/llvm-project/commit/dde23bf98ecb309dd36405cff7270c613834a534.diff
LOG: [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
Added:
Modified:
llvm/test/tools/llvm-lipo/replace-invalid-input.test
llvm/test/tools/llvm-lipo/segalign-invalid-input.test
llvm/tools/llvm-lipo/llvm-lipo.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-lipo/replace-invalid-input.test b/llvm/test/tools/llvm-lipo/replace-invalid-input.test
index c0ea4d7830919..214f6218f1803 100644
--- a/llvm/test/tools/llvm-lipo/replace-invalid-input.test
+++ b/llvm/test/tools/llvm-lipo/replace-invalid-input.test
@@ -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
diff --git a/llvm/test/tools/llvm-lipo/segalign-invalid-input.test b/llvm/test/tools/llvm-lipo/segalign-invalid-input.test
index aa6aceb77cc73..48a625e475610 100644
--- a/llvm/test/tools/llvm-lipo/segalign-invalid-input.test
+++ b/llvm/test/tools/llvm-lipo/segalign-invalid-input.test
@@ -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
diff --git a/llvm/tools/llvm-lipo/llvm-lipo.cpp b/llvm/tools/llvm-lipo/llvm-lipo.cpp
index 43dd97ed2c3be..a1247a30734a8 100644
--- a/llvm/tools/llvm-lipo/llvm-lipo.cpp
+++ b/llvm/tools/llvm-lipo/llvm-lipo.cpp
@@ -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);
More information about the llvm-commits
mailing list