From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 6FDE1384DD04; Thu, 18 Apr 2024 01:02:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6FDE1384DD04 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1713402147; bh=tpWHtrvMyHL6cNuvFF9L2Rt+awQSmiWZOwKJmhV6Was=; h=From:To:Subject:Date:From; b=q1HEyjdHB2dvTOQT3vffM0woU8+9MmB2vPpF/KFeIFQXisW++nR+b8Fah5cqNrjkU oLhFMn08w7MZeRxXP2sEmS1dRoOPSq3+LHSy0FIXMoqG0m98USjQn/6Q4KBsaZg/dM EHhAszyuHOfFwDmOgCRjCATr6uielwPYe9XtWPO0= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: binutils-cvs@sourceware.org Subject: [binutils-gdb] Tidy objdump opb expressions X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: 1c8102d17f5e56796adb27d9a9180f2c5013b913 X-Git-Newrev: 170957ff9b847cf44f6121fd846f5483f2090afd Message-Id: <20240418010227.6FDE1384DD04@sourceware.org> Date: Thu, 18 Apr 2024 01:02:27 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D170957ff9b84= 7cf44f6121fd846f5483f2090afd commit 170957ff9b847cf44f6121fd846f5483f2090afd Author: Alan Modra Date: Wed Apr 17 18:16:55 2024 +0930 Tidy objdump opb expressions =20 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. =20 * 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] !=3D 0) break; if (! disassemble_zeroes && (inf->insn_info_valid =3D=3D 0 || inf->branch_delay_insns =3D=3D 0) && (octets >=3D skip_zeroes - || (addr_offset * opb + octets =3D=3D stop_offset * opb + || (octets =3D=3D (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 !=3D stop_offset * opb) + if (octets !=3D (stop_offset - addr_offset) * opb) octets &=3D ~3; =20 /* 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; =20 octets =3D octets_per_line; - if (addr_offset + octets / opb > stop_offset) + if (octets / opb > stop_offset - addr_offset) octets =3D (stop_offset - addr_offset) * opb; =20 for (j =3D addr_offset * opb; j < addr_offset * opb + octets; ++j)