aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2005-04-14 02:27:56 +0000
committerAlan Modra <amodra@gmail.com>2005-04-14 02:27:56 +0000
commit92ceba1e4f12b335f6161d08a52c62a9c7954fe0 (patch)
tree3e51e61a169c011ba068b5459732b8c6d5f9c318
parentab70e2a569bcef40653fc3cad7ddf64d24256433 (diff)
downloadgdb-92ceba1e4f12b335f6161d08a52c62a9c7954fe0.zip
gdb-92ceba1e4f12b335f6161d08a52c62a9c7954fe0.tar.gz
gdb-92ceba1e4f12b335f6161d08a52c62a9c7954fe0.tar.bz2
* merge.c (sec_merge_emit): Tidy. Check for bfd_zmalloc errors.
Write trailing padding.
-rw-r--r--bfd/ChangeLog3
-rw-r--r--bfd/merge.c35
2 files changed, 27 insertions, 11 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 6e66048..cd93c38 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,8 @@
2005-04-14 Alan Modra <amodra@bigpond.net.au>
+ * merge.c (sec_merge_emit): Tidy. Check for bfd_zmalloc errors.
+ Write trailing padding.
+
* merge.c (merge_strings): Round up section size for alignment.
2005-04-14 David S. Miller <davem@davemloft.net>
diff --git a/bfd/merge.c b/bfd/merge.c
index da826c7..ccbf5b7 100644
--- a/bfd/merge.c
+++ b/bfd/merge.c
@@ -288,24 +288,27 @@ sec_merge_emit (bfd *abfd, struct sec_merge_hash_entry *entry)
{
struct sec_merge_sec_info *secinfo = entry->secinfo;
asection *sec = secinfo->sec;
- char *pad = "";
+ char *pad = NULL;
bfd_size_type off = 0;
int alignment_power = sec->output_section->alignment_power;
if (alignment_power)
- pad = bfd_zmalloc ((bfd_size_type) 1 << alignment_power);
+ {
+ pad = bfd_zmalloc ((bfd_size_type) 1 << alignment_power);
+ if (pad == NULL)
+ return FALSE;
+ }
for (; entry != NULL && entry->secinfo == secinfo; entry = entry->next)
{
- register const char *str;
- register size_t len;
+ const char *str;
+ bfd_size_type len;
- len = off & (entry->alignment - 1);
- if (len)
+ len = -off & (entry->alignment - 1);
+ if (len != 0)
{
- len = entry->alignment - len;
if (bfd_bwrite (pad, len, abfd) != len)
- break;
+ goto err;
off += len;
}
@@ -313,15 +316,25 @@ sec_merge_emit (bfd *abfd, struct sec_merge_hash_entry *entry)
len = entry->len;
if (bfd_bwrite (str, len, abfd) != len)
- break;
+ goto err;
off += len;
}
- if (alignment_power)
+ /* Trailing alignment needed? */
+ off = sec->size - off;
+ if (off != 0
+ && bfd_bwrite (pad, off, abfd) != off)
+ goto err;
+
+ if (pad != NULL)
free (pad);
+ return TRUE;
- return entry == NULL || entry->secinfo != secinfo;
+ err:
+ if (pad != NULL)
+ free (pad);
+ return FALSE;
}
/* Register a SEC_MERGE section as a candidate for merging.