When iterating over AR archive members like
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <libelf.h>
int main(int argc, char **argv)
{
int fd;
Elf *e, *parent;
elf_version (EV_CURRENT);
fd = open (argv[1], O_RDONLY);
parent = elf_begin (fd, ELF_C_READ, NULL);
while ((e = elf_begin (fd, ELF_C_READ, parent)) != NULL)
{
Elf_Arhdr *h = elf_getarhdr (e);
fprintf (stderr, "%llu: %s\n", elf_getaroff (e), h->ar_name);
elf_next (e);
elf_end (e);
}
return 0;
}
the iteration does not stop but instead the last archive member
keeps being opened again and again and elf_getaroff keeps
increasing.
Take
/tmp$ ar t t.a
t2.o
t1.o
/tmp$ ./t t.a 2>&1 | head
8: /
120: t2.o
1658: t1.o
3494: t1.o
5330: t1.o
7166: t1.o
9002: t1.o
10838: t1.o
12674: t1.o
14510: t1.o
Observed with elfutils 0.143.
Richard.
--
Richard Guenther <rguenther(a)suse.de>
Novell / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 - GF: Markus Rex