From d1721dc12fea15bb4fcee56ba1fad15bb23796d7 Mon Sep 17 00:00:00 2001 From: Armaan Sandhu Date: Sun, 1 Nov 2026 19:59:18 -0500 Subject: [PATCH] main: don't parse the -r repeat count again as a -c option after reading c from "-r1c2" nothing is left in the argument, but the code only checks for the m mark, so it rewinds to just after the time and "c2" gets parsed as "-c 2". that selects commands starting with "2" insted of limiting the repeats. stop when the argument is used up. the repeat test only counted the ======= markers, wich still come out right, so also check that the process gets listed. --- src/main.c | 3 +++ tests/case-20-repeat-count.bash | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/main.c b/src/main.c index a82bbac4..4946bc89 100644 --- a/src/main.c +++ b/src/main.c @@ -798,6 +798,9 @@ int main(int argc, char *argv[]) { RptMaxCount = i; } + if (!*cp) + break; + if (*cp != LSOF_FID_MARK) { GOx1 = GObk[0]; GOx2 = GObk[1] + n; diff --git a/tests/case-20-repeat-count.bash b/tests/case-20-repeat-count.bash index 6962bc63..5b544685 100755 --- a/tests/case-20-repeat-count.bash +++ b/tests/case-20-repeat-count.bash @@ -16,4 +16,11 @@ if [ $(echo "$output" | grep -e '=======' | wc -l) != 5 ]; then exit 1 fi +# The count must not be parsed again as a -c option +output=$(${lsof} -r1c2 -a -p $$ -Fp) +echo "$output" >> $report +if [ $(echo "$output" | grep -e "^p$$\$" | wc -l) != 2 ]; then + exit 1 +fi + exit 0