From 1fd768057cd0c4fc6ed47e1a9b77ffed2fe608e9 Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 8 Jul 2024 11:45:01 -0600 Subject: [PATCH] swab(1): don't accept positional arguments --- src/swab.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/swab.rs b/src/swab.rs index 7889a59..5b4c173 100644 --- a/src/swab.rs +++ b/src/swab.rs @@ -48,7 +48,8 @@ fn main() -> ExitCode { let mut input = stdin(); let mut output = stdout().lock(); - let mut wordsize: usize = 2; + let mut optind: usize = 1; // argv[0] + let mut wordsize: usize = 2; // Equivalent to dd(1p). while let Some(opt) = argv.getopt(":w:") { match opt.opt() { @@ -59,11 +60,16 @@ fn main() -> ExitCode { _ => { return usage(&argv[0]); }, } } + optind = opt.ind(); }, _ => { return usage(&argv[0]); } } } + if optind < argv.len() { + return usage(&argv[0]); + } + buf.resize(wordsize, 0); loop {