aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-02-27 14:11:35 +1030
committerAlan Modra <amodra@gmail.com>2020-02-27 17:05:08 +1030
commit05f52dc2e1359fc4f69fab5c39fdfdf5efe93a15 (patch)
tree50c9779e73202841b6ecd33b3bd50949ac06b2fa /bfd
parentff69a8949bb65c9eb64ea03ee1492902c2620c8c (diff)
downloadfsf-binutils-gdb-05f52dc2e1359fc4f69fab5c39fdfdf5efe93a15.zip
fsf-binutils-gdb-05f52dc2e1359fc4f69fab5c39fdfdf5efe93a15.tar.gz
fsf-binutils-gdb-05f52dc2e1359fc4f69fab5c39fdfdf5efe93a15.tar.bz2
_bfd_xcoff_read_ar_hdr tidy
* coff-rs6000.c (_bfd_xcoff_read_ar_hdr): Put all data in one malloc'd block.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog5
-rw-r--r--bfd/coff-rs6000.c48
2 files changed, 22 insertions, 31 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index ff03baa..e5cf5e1 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,10 @@
2020-02-27 Alan Modra <amodra@gmail.com>
+ * coff-rs6000.c (_bfd_xcoff_read_ar_hdr): Put all data in one
+ malloc'd block.
+
+2020-02-27 Alan Modra <amodra@gmail.com>
+
* bfd.c (bfd_stat_arch_elt): Use vector of containing archive,
if file is an archive element.
* bfd-in2.h: Regenerate.
diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c
index 8b8f472..1cc708c 100644
--- a/bfd/coff-rs6000.c
+++ b/bfd/coff-rs6000.c
@@ -1491,32 +1491,23 @@ _bfd_xcoff_read_ar_hdr (bfd *abfd)
{
bfd_size_type namlen;
struct areltdata *ret;
- bfd_size_type amt = sizeof (struct areltdata);
-
- ret = (struct areltdata *) bfd_zmalloc (amt);
- if (ret == NULL)
- return NULL;
+ bfd_size_type amt;
if (! xcoff_big_format_p (abfd))
{
struct xcoff_ar_hdr hdr;
struct xcoff_ar_hdr *hdrp;
- if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
- != SIZEOF_AR_HDR)
- {
- free (ret);
- return NULL;
- }
+ if (bfd_bread (&hdr, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR)
+ return NULL;
GET_VALUE_IN_FIELD (namlen, hdr.namlen, 10);
- amt = SIZEOF_AR_HDR + namlen + 1;
- hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd, amt);
- if (hdrp == NULL)
- {
- free (ret);
- return NULL;
- }
+ amt = sizeof (struct areltdata) + SIZEOF_AR_HDR + namlen + 1;
+ ret = (struct areltdata *) bfd_malloc (amt);
+ if (ret == NULL)
+ return ret;
+
+ hdrp = (struct xcoff_ar_hdr *) (ret + 1);
memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR, namlen, abfd) != namlen)
{
@@ -1534,21 +1525,16 @@ _bfd_xcoff_read_ar_hdr (bfd *abfd)
struct xcoff_ar_hdr_big hdr;
struct xcoff_ar_hdr_big *hdrp;
- if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
- != SIZEOF_AR_HDR_BIG)
- {
- free (ret);
- return NULL;
- }
+ if (bfd_bread (&hdr, SIZEOF_AR_HDR_BIG, abfd) != SIZEOF_AR_HDR_BIG)
+ return NULL;
GET_VALUE_IN_FIELD (namlen, hdr.namlen, 10);
- amt = SIZEOF_AR_HDR_BIG + namlen + 1;
- hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd, amt);
- if (hdrp == NULL)
- {
- free (ret);
- return NULL;
- }
+ amt = sizeof (struct areltdata) + SIZEOF_AR_HDR_BIG + namlen + 1;
+ ret = (struct areltdata *) bfd_malloc (amt);
+ if (ret == NULL)
+ return ret;
+
+ hdrp = (struct xcoff_ar_hdr_big *) (ret + 1);
memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG);
if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR_BIG, namlen, abfd) != namlen)
{