public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@sourceware.org>
To: binutils-cvs@sourceware.org
Subject: [binutils-gdb] Tidy objdump opb expressions
Date: Thu, 18 Apr 2024 01:02:27 +0000 (GMT)	[thread overview]
Message-ID: <20240418010227.6FDE1384DD04@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=170957ff9b847cf44f6121fd846f5483f2090afd

commit 170957ff9b847cf44f6121fd846f5483f2090afd
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Apr 17 18:16:55 2024 +0930

    Tidy objdump opb expressions
    
    I don't think any of these can overflow, but since all of the
    expressions I'm editing here are inside a while loop with condition
    addr_offset < stop_offset, this change makes it more obvious that they
    can't overflow.
    
            * objdump.c (disassemble_bytes): Calculate octet expressions
            involving both addr_offset and stop_offset by first
            subtracting addr_offset from stop_offset.

Diff:
---
 binutils/objdump.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/binutils/objdump.c b/binutils/objdump.c
index 6396174d50f..f92e14b33e4 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -3356,28 +3356,28 @@ disassemble_bytes (struct disassemble_info *inf,
       /* If we see more than SKIP_ZEROES octets of zeroes, we just
 	 print `...'.  */
       if (! disassemble_zeroes)
-	for (; addr_offset * opb + octets < stop_offset * opb; octets++)
+	for (; octets < (stop_offset - addr_offset) * opb; octets++)
 	  if (data[addr_offset * opb + octets] != 0)
 	    break;
       if (! disassemble_zeroes
 	  && (inf->insn_info_valid == 0
 	      || inf->branch_delay_insns == 0)
 	  && (octets >= skip_zeroes
-	      || (addr_offset * opb + octets == stop_offset * opb
+	      || (octets == (stop_offset - addr_offset) * opb
 		  && octets < skip_zeroes_at_end)))
 	{
 	  /* If there are more nonzero octets to follow, we only skip
 	     zeroes in multiples of 4, to try to avoid running over
 	     the start of an instruction which happens to start with
 	     zero.  */
-	  if (addr_offset * opb + octets != stop_offset * opb)
+	  if (octets != (stop_offset - addr_offset) * opb)
 	    octets &= ~3;
 
 	  /* If we are going to display more data, and we are displaying
 	     file offsets, then tell the user how many zeroes we skip
 	     and the file offset from where we resume dumping.  */
 	  if (display_file_offsets
-	      && addr_offset + octets / opb < stop_offset)
+	      && octets / opb < stop_offset - addr_offset)
 	    printf (_("\t... (skipping %lu zeroes, "
 		      "resuming at file offset: 0x%lx)\n"),
 		    (unsigned long) (octets / opb),
@@ -3529,7 +3529,7 @@ disassemble_bytes (struct disassemble_info *inf,
 	      bfd_vma j;
 
 	      octets = octets_per_line;
-	      if (addr_offset + octets / opb > stop_offset)
+	      if (octets / opb > stop_offset - addr_offset)
 		octets = (stop_offset - addr_offset) * opb;
 
 	      for (j = addr_offset * opb; j < addr_offset * opb + octets; ++j)

                 reply	other threads:[~2024-04-18  1:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240418010227.6FDE1384DD04@sourceware.org \
    --to=amodra@sourceware.org \
    --cc=binutils-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).