This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] Don't call bfd_get_file_size in _bfd_generic_get_section_contents
- From: Alan Modra <amodra at gmail dot com>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>
- Cc: binutils at sourceware dot org
- Date: Wed, 28 Jun 2017 10:24:44 +0930
- Subject: Re: [PATCH] Don't call bfd_get_file_size in _bfd_generic_get_section_contents
- Authentication-results: sourceware.org; auth=none
- References: <20170627125326.GA6859@gmail.com>
On Tue, Jun 27, 2017 at 05:53:26AM -0700, H.J. Lu wrote:
> diff --git a/bfd/libbfd.c b/bfd/libbfd.c
> index 0d9de2b..82cffb8 100644
> --- a/bfd/libbfd.c
> +++ b/bfd/libbfd.c
> @@ -788,8 +788,7 @@ _bfd_generic_get_section_contents (bfd *abfd,
> file_ptr offset,
> bfd_size_type count)
> {
> - bfd_size_type sz;
> - ufile_ptr filesz;
> + bfd_size_type sz, end;
> if (count == 0)
> return TRUE;
>
> @@ -812,10 +811,12 @@ _bfd_generic_get_section_contents (bfd *abfd,
> sz = section->rawsize;
> else
> sz = section->size;
> - filesz = bfd_get_file_size (abfd);
> - if (offset + count < count
> - || offset + count > sz
> - || (ufile_ptr) section->filepos + offset + count > filesz)
> + end = offset + count;
It's possible for offset, a file_ptr, to be of a larger integer type
than count, a bfd_size_type. The reverse is also true. For that
reason, don't introduce the temp var "end".
OK without that change.
--
Alan Modra
Australia Development Lab, IBM