From a44e8a03e3384b7a7a5e1def7db754a90d823ac2 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Wed, 6 Jul 2022 13:41:30 -0700 Subject: [PATCH] main: fix switch-or-option argh wrapper nits Fix two small bugs in the code that handles options that are valid with or without extra options (--battery, --video-encoder, --video-decoder, --gpu, and --gpu-display): - If the next arg was a short option (e.g. `-p`), we didn't consider it the start of a new flag, so it would have been used as the parameters for a switch-or-option arg (e.g. `--gpu -p something` would parse as `--gpu=-p`). Fix this by only requiring a single dash instead of two. - The `crosvm run` command requires a positional argument at the end (kernel filename), and the check for the switch-or-option arg had an off-by-one that did not consider the positional argument. This broke the case where one of these switches occurred right before the kernel filename argument, e.g. `crosvm run [...] --gpu vm_kernel`. Fix this by comparing against len - 2 instead of len - 1. BUG=b:237334804 TEST=crosvm run --battery -p init=/bin/bash -r vm_rootfs.img vm_kernel TEST=crosvm run -p init=/bin/bash -r vm_roofs.img --battery vm_kernel Change-Id: I2c44ca124ba35b980e655f4f0cf9a9366e6be33d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3749939 Tested-by: kokoro Reviewed-by: Dennis Kempin Reviewed-by: Alexandre Courbot Commit-Queue: Daniel Verkamp --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 3cd2d4f2b7..8f963d1faf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -447,7 +447,7 @@ fn crosvm_main() -> Result { ]; for arg in switch_or_option { if let Some(i) = args.iter().position(|a| a == arg) { - if i == args.len() - 1 || args[i + 1].starts_with("--") { + if i >= args.len() - 2 || args[i + 1].starts_with("-") { args.insert(i + 1, "".to_string()); } }