Created attachment 13880 [details] the result of eu-ar -x -N COUNT eu-ar -x -N COUNT should use instance [COUNT] of name, but it uses instance [COUNT+1] of name incorrectly. Usage: -N Use instance [COUNT] of name. The attachments show the differences of command result between "eu-ar -x -N COUNT" and "ar -x -N COUNT". do_oper_extract() in src/ar.c Is it should be instance-- at Line522? 522 if (res != NULL && (instance < 0 || instance-- == 0) 523 && !found[(char **) res->data - argv]) 524 found[(char **) res->data - argv] = do_extract = true; 525 }
Created attachment 13881 [details] the result of ar -x -N COUNT
Please pay attention on this issue. When using instance [COUNT] of name, the instance of check is wrong in do_oper_extract(). instance-- should be --instance. 522 if (res != NULL && (instance < 0 || instance-- == 0) 523 && !found[(char **) res->data - argv]) 524 found[(char **) res->data - argv] = do_extract = true; 525 }
Thanks for the report and analysis. Next time please post output as text instead of an image. I posted a patch that includes a testcase: https://inbox.sourceware.org/elfutils-devel/20220828155746.99653-1-mark@klomp.org/T/#u
commit 6cb01b4ef3cdd4f83d21bbcec72fa66712ac14e6 Author: Mark Wielaard <mark@klomp.org> Date: Sun Aug 28 17:46:08 2022 +0200 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>