aoutx.h tidy

Save a multiplication, and any concern that the buffer allocation
might be smaller than the amount read (as it could be if the header
size isn't a multiple of EXTERNAL_NLIST_SIZE).

	* aoutx.h (aout_get_external_symbols): Tidy allocation of symbol buffer.
This commit is contained in:
Alan Modra 2014-11-07 20:18:25 +10:30
parent 67be31e5aa
commit 7c53fd1ca3
2 changed files with 14 additions and 14 deletions

View File

@ -1,3 +1,7 @@
2014-11-07 Alan Modra <amodra@gmail.com>
* aoutx.h (aout_get_external_symbols): Tidy allocation of symbol buffer.
2014-11-07 Alan Modra <amodra@gmail.com> 2014-11-07 Alan Modra <amodra@gmail.com>
* archive.c (_bfd_slurp_extended_name_table): Revert bfd_get_size check. * archive.c (_bfd_slurp_extended_name_table): Revert bfd_get_size check.

View File

@ -1300,14 +1300,14 @@ aout_get_external_symbols (bfd *abfd)
{ {
bfd_size_type count; bfd_size_type count;
struct external_nlist *syms; struct external_nlist *syms;
bfd_size_type amt = exec_hdr (abfd)->a_syms;
count = exec_hdr (abfd)->a_syms / EXTERNAL_NLIST_SIZE; count = amt / EXTERNAL_NLIST_SIZE;
if (count == 0) if (count == 0)
return TRUE; /* Nothing to do. */ return TRUE; /* Nothing to do. */
#ifdef USE_MMAP #ifdef USE_MMAP
if (! bfd_get_file_window (abfd, obj_sym_filepos (abfd), if (! bfd_get_file_window (abfd, obj_sym_filepos (abfd), amt,
exec_hdr (abfd)->a_syms,
&obj_aout_sym_window (abfd), TRUE)) &obj_aout_sym_window (abfd), TRUE))
return FALSE; return FALSE;
syms = (struct external_nlist *) obj_aout_sym_window (abfd).data; syms = (struct external_nlist *) obj_aout_sym_window (abfd).data;
@ -1315,20 +1315,16 @@ aout_get_external_symbols (bfd *abfd)
/* We allocate using malloc to make the values easy to free /* We allocate using malloc to make the values easy to free
later on. If we put them on the objalloc it might not be later on. If we put them on the objalloc it might not be
possible to free them. */ possible to free them. */
syms = (struct external_nlist *) bfd_malloc (count * EXTERNAL_NLIST_SIZE); syms = (struct external_nlist *) bfd_malloc (amt);
if (syms == NULL) if (syms == NULL)
return FALSE; return FALSE;
{ if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
bfd_size_type amt; || bfd_bread (syms, amt, abfd) != amt)
amt = exec_hdr (abfd)->a_syms; {
if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0 free (syms);
|| bfd_bread (syms, amt, abfd) != amt) return FALSE;
{ }
free (syms);
return FALSE;
}
}
#endif #endif
obj_aout_external_syms (abfd) = syms; obj_aout_external_syms (abfd) = syms;