summaryrefslogtreecommitdiff
path: root/src/ar.c
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2022-08-28 17:46:08 +0200
committerMark Wielaard <mark@klomp.org>2022-09-14 20:48:29 +0200
commit6cb01b4ef3cdd4f83d21bbcec72fa66712ac14e6 (patch)
tree5e37ea849e6d667903ff56623f5bc4ea0b8925b5 /src/ar.c
parentee188125b10d1588a0536af033d7b7b1bbbaafaf (diff)
downloadelfutils-6cb01b4ef3cdd4f83d21bbcec72fa66712ac14e6.tar.gz
ar: Correct -N COUNT off-by-one
When using instance [COUNT], the instance check is wrong. instance-- == 0 should be --instance == 0. Add a testcase run-ar-N.sh that uses -N COUNT with extract and delete operations checking the right instance was extracted and deleted. https://sourceware.org/bugzilla/show_bug.cgi?id=28725 Reported-by: panxiaohe <panxh_ran@163.com> Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'src/ar.c')
-rw-r--r--src/ar.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/ar.c b/src/ar.c
index 9e8df120..04456c18 100644
--- a/src/ar.c
+++ b/src/ar.c
@@ -518,7 +518,7 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc,
ENTRY entry;
entry.key = arhdr->ar_name;
ENTRY *res = hsearch (entry, FIND);
- if (res != NULL && (instance < 0 || instance-- == 0)
+ if (res != NULL && (instance < 0 || --instance == 0)
&& !found[(char **) res->data - argv])
found[(char **) res->data - argv] = do_extract = true;
}
@@ -952,7 +952,7 @@ do_oper_delete (const char *arfname, char **argv, int argc,
ENTRY entry;
entry.key = arhdr->ar_name;
ENTRY *res = hsearch (entry, FIND);
- if (res != NULL && (instance < 0 || instance-- == 0)
+ if (res != NULL && (instance < 0 || --instance == 0)
&& !found[(char **) res->data - argv])
found[(char **) res->data - argv] = do_delete = true;
}