summaryrefslogtreecommitdiff
path: root/libdwfl
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2020-11-12 16:04:01 +0100
committerMark Wielaard <mark@klomp.org>2020-11-19 12:16:45 +0100
commitd745b47b8386a7972edb70e97857c076c45b3b5d (patch)
tree25811adaed21f0627665c26c0f7c46b0483ef14c /libdwfl
parent4d5fd1909f89b0db7d2f00e6a0f7e91fabc94f8a (diff)
downloadelfutils-d745b47b8386a7972edb70e97857c076c45b3b5d.tar.gz
segment_report_module: Remove nested finish() function
This works just as well with a goto-out style label. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog5
-rw-r--r--libdwfl/dwfl_segment_report_module.c50
2 files changed, 28 insertions, 27 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 791cb870..59ef37aa 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,5 +1,10 @@
2020-11-12 Timm Bäder <tbaeder@redhat.com>
+ * dwfl_segment_report_module.c (dwfl_segment_report_module): Remove
+ finish function, replace with goto out.
+
+2020-11-12 Timm Bäder <tbaeder@redhat.com>
+
* dwfl_segment_report_module.c (dwfl_segment_report_module): Declare
p32 and p64 as pointers instead of arrays.
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index dd3fdb9e..c7725002 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -282,21 +282,10 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
here so we can always safely free it. */
void *phdrsp = NULL;
- inline int finish (void)
- {
- free (phdrsp);
- release_buffer (&buffer, &buffer_available);
- if (elf != NULL)
- elf_end (elf);
- if (fd != -1)
- close (fd);
- return ndx;
- }
-
if (segment_read (ndx, &buffer, &buffer_available,
start, sizeof (Elf64_Ehdr))
|| memcmp (buffer, ELFMAG, SELFMAG) != 0)
- return finish ();
+ goto out;
inline bool read_portion (void **data, size_t *data_size,
GElf_Addr vaddr, size_t filesz)
@@ -363,13 +352,13 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
case ELFCLASS32:
xlatefrom.d_size = sizeof (Elf32_Ehdr);
if (elf32_xlatetom (&xlateto, &xlatefrom, ei_data) == NULL)
- return finish ();
+ goto out;
e_type = ehdr.e32.e_type;
phoff = ehdr.e32.e_phoff;
phnum = ehdr.e32.e_phnum;
phentsize = ehdr.e32.e_phentsize;
if (phentsize != sizeof (Elf32_Phdr))
- return finish ();
+ goto out;
/* NOTE if the number of sections is > 0xff00 then e_shnum
is zero and the actual number would come from the section
zero sh_size field. We ignore this here because getting shdrs
@@ -381,19 +370,19 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
case ELFCLASS64:
xlatefrom.d_size = sizeof (Elf64_Ehdr);
if (elf64_xlatetom (&xlateto, &xlatefrom, ei_data) == NULL)
- return finish ();
+ goto out;
e_type = ehdr.e64.e_type;
phoff = ehdr.e64.e_phoff;
phnum = ehdr.e64.e_phnum;
phentsize = ehdr.e64.e_phentsize;
if (phentsize != sizeof (Elf64_Phdr))
- return finish ();
+ goto out;
/* See the NOTE above for shdrs_end and ehdr.e32.e_shnum. */
shdrs_end = ehdr.e64.e_shoff + ehdr.e64.e_shnum * ehdr.e64.e_shentsize;
break;
default:
- return finish ();
+ goto out;
}
/* The file header tells where to find the program headers.
@@ -401,7 +390,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
Without them, we don't have a module to report. */
if (phnum == 0)
- return finish ();
+ goto out;
xlatefrom.d_type = xlateto.d_type = ELF_T_PHDR;
xlatefrom.d_size = phnum * phentsize;
@@ -410,7 +399,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
size_t ph_buffer_size = 0;
if (read_portion (&ph_buffer, &ph_buffer_size,
start + phoff, xlatefrom.d_size))
- return finish ();
+ goto out;
/* ph_buffer_size will be zero if we got everything from the initial
buffer, otherwise it will be the size of the new buffer that
@@ -423,11 +412,11 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
bool class32 = ei_class == ELFCLASS32;
size_t phdr_size = class32 ? sizeof (Elf32_Phdr) : sizeof (Elf64_Phdr);
if (unlikely (phnum > SIZE_MAX / phdr_size))
- return finish ();
+ goto out;
const size_t phdrsp_bytes = phnum * phdr_size;
phdrsp = malloc (phdrsp_bytes);
if (unlikely (phdrsp == NULL))
- return finish ();
+ goto out;
xlateto.d_buf = phdrsp;
xlateto.d_size = phdrsp_bytes;
@@ -638,7 +627,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
if (unlikely (!found_bias))
{
free (build_id);
- return finish ();
+ goto out;
}
/* Now we know enough to report a module for sure: its bounds. */
@@ -709,7 +698,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
if (skip_this_module)
{
free (build_id);
- return finish ();
+ goto out;
}
}
@@ -799,7 +788,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
Elf32_Dyn *d32 = dyns;
Elf64_Dyn *d64 = dyns;
if (unlikely (dyns == NULL))
- return finish ();
+ goto out;
xlatefrom.d_type = xlateto.d_type = ELF_T_DYN;
xlatefrom.d_buf = (void *) dyn_data;
@@ -889,7 +878,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
if (unlikely (mod == NULL))
{
ndx = -1;
- return finish ();
+ goto out;
}
/* We have reported the module. Now let the caller decide whether we
@@ -913,7 +902,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
void *contents = calloc (1, file_trimmed_end);
if (unlikely (contents == NULL))
- return finish ();
+ goto out;
inline void final_read (size_t offset, GElf_Addr vaddr, size_t size)
{
@@ -975,5 +964,12 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
mod->main_bias = bias;
}
- return finish ();
+out:
+ free (phdrsp);
+ release_buffer (&buffer, &buffer_available);
+ if (elf != NULL)
+ elf_end (elf);
+ if (fd != -1)
+ close (fd);
+ return ndx;
}