public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: tbaeder@redhat.com
To: elfutils-devel@sourceware.org
Subject: [PATCH 3/5] readelf: Pull left() info file scope
Date: Fri,  8 Jan 2021 09:16:31 +0100	[thread overview]
Message-ID: <20210108081633.2202592-4-tbaeder@redhat.com> (raw)
In-Reply-To: <20210108081633.2202592-1-tbaeder@redhat.com>

From: Timm Bäder <tbaeder@redhat.com>

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
---
 src/readelf.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/readelf.c b/src/readelf.c
index 0157f8a2..99e90c34 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -3571,6 +3571,13 @@ print_liblist (Ebl *ebl)
     }
 }
 
+static inline size_t
+left (Elf_Data *data,
+      const unsigned char *p)
+{
+  return (const unsigned char *) data->d_buf + data->d_size - p;
+}
+
 static void
 print_attributes (Ebl *ebl, const GElf_Ehdr *ehdr)
 {
@@ -3615,13 +3622,8 @@ print_attributes (Ebl *ebl, const GElf_Ehdr *ehdr)
 
       fputs_unlocked (_("  Owner          Size\n"), stdout);
 
-      inline size_t left (void)
-      {
-	return (const unsigned char *) data->d_buf + data->d_size - p;
-      }
-
       /* Loop over the sections.  */
-      while (left () >= 4)
+      while (left (data, p) >= 4)
 	{
 	  /* Section length.  */
 	  uint32_t len;
@@ -3630,7 +3632,7 @@ print_attributes (Ebl *ebl, const GElf_Ehdr *ehdr)
 	  if (MY_ELFDATA != ehdr->e_ident[EI_DATA])
 	    CONVERT (len);
 
-	  if (unlikely (len > left ()))
+	  if (unlikely (len > left (data, p)))
 	    break;
 
 	  /* Section vendor name.  */
-- 
2.26.2


  parent reply	other threads:[~2021-01-08  8:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-08  8:16 Remove nested functions from readelf.c tbaeder
2021-01-08  8:16 ` [PATCH 1/5] readelf: Pull add_dump_section() into file scope tbaeder
2021-01-30 19:55   ` Mark Wielaard
2021-01-08  8:16 ` [PATCH 2/5] readelf: Pull same_set() info " tbaeder
2021-01-30 20:14   ` Mark Wielaard
2021-01-08  8:16 ` tbaeder [this message]
2021-01-30 20:29   ` [PATCH 3/5] readelf: Pull left() " Mark Wielaard
2021-01-08  8:16 ` [PATCH 4/5] readelf: Pull regname() into " tbaeder
2021-01-30 20:47   ` Mark Wielaard
2021-01-08  8:16 ` [PATCH 5/5] readelf: Pull advance_pc() " tbaeder
2021-02-01 14:21 ` Remove nested functions from readelf.c Mark Wielaard
2021-02-02 10:07   ` Timm Bäder

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=20210108081633.2202592-4-tbaeder@redhat.com \
    --to=tbaeder@redhat.com \
    --cc=elfutils-devel@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).