aboutsummaryrefslogtreecommitdiff
path: root/bfd/elflink.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2008-02-23 00:02:05 +0000
committerH.J. Lu <hjl.tools@gmail.com>2008-02-23 00:02:05 +0000
commit3ae181ee8903e608d34e41dc92a28b22808bc495 (patch)
tree3d63a89b3456eea1e9ade80bd7f35b14d0f9fc99 /bfd/elflink.c
parent6456897f67bd2eb34b0ec18108b52477bfabc2ff (diff)
downloadgdb-3ae181ee8903e608d34e41dc92a28b22808bc495.zip
gdb-3ae181ee8903e608d34e41dc92a28b22808bc495.tar.gz
gdb-3ae181ee8903e608d34e41dc92a28b22808bc495.tar.bz2
2008-02-22 H.J. Lu <hongjiu.lu@intel.com>
PR ld/5788 * elflink.c (elf_create_symbuf): Correct buffer size and position.
Diffstat (limited to 'bfd/elflink.c')
-rw-r--r--bfd/elflink.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c
index ab19be2..3a00a51 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -6870,7 +6870,7 @@ elf_create_symbuf (bfd_size_type symcount, Elf_Internal_Sym *isymbuf)
Elf_Internal_Sym **ind, **indbufend, **indbuf;
struct elf_symbuf_symbol *ssym;
struct elf_symbuf_head *ssymbuf, *ssymhead;
- bfd_size_type i, shndx_count;
+ bfd_size_type i, shndx_count, total_size;
indbuf = bfd_malloc2 (symcount, sizeof (*indbuf));
if (indbuf == NULL)
@@ -6890,15 +6890,16 @@ elf_create_symbuf (bfd_size_type symcount, Elf_Internal_Sym *isymbuf)
if (ind[0]->st_shndx != ind[1]->st_shndx)
shndx_count++;
- ssymbuf = bfd_malloc ((shndx_count + 1) * sizeof (*ssymbuf)
- + (indbufend - indbuf) * sizeof (*ssymbuf));
+ total_size = ((shndx_count + 1) * sizeof (*ssymbuf)
+ + (indbufend - indbuf) * sizeof (*ssym));
+ ssymbuf = bfd_malloc (total_size);
if (ssymbuf == NULL)
{
free (indbuf);
return NULL;
}
- ssym = (struct elf_symbuf_symbol *) (ssymbuf + shndx_count);
+ ssym = (struct elf_symbuf_symbol *) (ssymbuf + shndx_count + 1);
ssymbuf->ssym = NULL;
ssymbuf->count = shndx_count;
ssymbuf->st_shndx = 0;
@@ -6916,7 +6917,9 @@ elf_create_symbuf (bfd_size_type symcount, Elf_Internal_Sym *isymbuf)
ssym->st_other = (*ind)->st_other;
ssymhead->count++;
}
- BFD_ASSERT ((bfd_size_type) (ssymhead - ssymbuf) == shndx_count);
+ BFD_ASSERT ((bfd_size_type) (ssymhead - ssymbuf) == shndx_count
+ && (((bfd_hostptr_t) ssym - (bfd_hostptr_t) ssymbuf)
+ == total_size));
free (indbuf);
return ssymbuf;