From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: PR29142, segv in ar with empty archive and libdeps specified
Date: Thu, 12 May 2022 13:25:00 +0930 [thread overview]
Message-ID: <YnyFFF7IZVI5KRDM@squeak.grove.modra.org> (raw)
PR 29142
* ar.c (main): Properly handle libdeps for zero file_count.
diff --git a/binutils/ar.c b/binutils/ar.c
index 0d4c7cf16a6..6f3f1d6946f 100644
--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -894,14 +894,16 @@ main (int argc, char **argv)
being operated on. We shouldn't use 1st slot, but we want
to avoid having to search all the way to the end of an
archive with a large number of members at link time. */
- new_files = xmalloc ((file_count + 2) * sizeof (char *));
- new_files[0] = files[0];
- new_files[1] = LIBDEPS;
- for (i = 1; i < file_count; i++)
- new_files[i+1] = files[i];
- file_count = ++i;
+ new_files = xmalloc ((file_count + 2) * sizeof (*new_files));
+ if (file_count)
+ {
+ new_files[0] = files[0];
+ memcpy (new_files + 1, files, file_count * sizeof (*files));
+ }
+ new_files[file_count != 0] = LIBDEPS;
+ file_count++;
+ new_files[file_count] = NULL;
files = new_files;
- files[i] = NULL;
}
switch (operation)
--
Alan Modra
Australia Development Lab, IBM
reply other threads:[~2022-05-12 3:55 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YnyFFF7IZVI5KRDM@squeak.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).