This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Re: PATCH octets vs bytes for objdump
- To: Ian Lance Taylor <ian at zembu dot com>
- Subject: Re: PATCH octets vs bytes for objdump
- From: Timothy Wall <twall at domesolutions dot com>
- Date: Wed, 26 Jan 2000 11:21:44 +0000
- CC: twall at tiac dot net, binutils at sourceware dot cygnus dot com, nickc at cygnus dot com
- Organization: Dome Solutions
- References: <388EE889.B8F033F3@tiac.net> <20000126153239.5690.qmail@daffy.airs.com>
So while algebraically they are equivalent, ISO C-ically they're not. Good
point.
The condition should be:
memaddr - info->buffer_vma + end_addr_offset > max_addr_offset
instead of:
memaddr + end_addr_offset > info->buffer_vma + max_addr_offset
T.
Ian Lance Taylor wrote:
> Date: Wed, 26 Jan 2000 07:28:57 -0500
> From: Timothy Wall <twall@tiac.net>
>
> *************** buffer_read_memory (memaddr, myaddr, len
> *** 29,39 ****
> int length;
> struct disassemble_info *info;
> {
> if (memaddr < info->buffer_vma
> ! || memaddr - info->buffer_vma + length > info->buffer_length)
> /* Out of bounds. Use EIO because GDB uses it. */
> return EIO;
> ! memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length);
> return 0;
> }
>
> --- 29,45 ----
> int length;
> struct disassemble_info *info;
> {
> + int opb = info->octets_per_byte;
> + int end_addr_offset = length / opb;
> + int max_addr_offset = info->buffer_length / opb;
> + int octets = (memaddr - info->buffer_vma) * opb;
> +
> if (memaddr < info->buffer_vma
> ! || memaddr + end_addr_offset > info->buffer_vma + max_addr_offset)
> /* Out of bounds. Use EIO because GDB uses it. */
> return EIO;
> ! memcpy (myaddr, info->buffer + octets, length);
> !
> return 0;
> }
>
> Note that the original version of the condition was careful to never
> form an address which extended past the end of the buffer. The new
> condition does not preserve that property, because memaddr +
> end_addr_offset might be past the end of the buffer. ISO C does not
> guarantee that you can form an address beyond the end of a buffer. I
> admit that this is just a quibble.
>
> Ian