diff mbox series

[v3,4/9] dump: Remove the section if when calculating the memory offset

Message ID 20220330123603.107120-5-frankja@linux.ibm.com
State New
Headers show
Series dump: Cleanup and consolidation | expand

Commit Message

Janosch Frank March 30, 2022, 12:35 p.m. UTC
When s->shdr_num is 0 we'll add 0 bytes of section headers which is
equivalent to not adding section headers but with the multiplication
we can remove a if/else.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 dump/dump.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

Comments

Marc-André Lureau March 31, 2022, 8:56 a.m. UTC | #1
On Wed, Mar 30, 2022 at 4:48 PM Janosch Frank <frankja@linux.ibm.com> wrote:

> When s->shdr_num is 0 we'll add 0 bytes of section headers which is
> equivalent to not adding section headers but with the multiplication
> we can remove a if/else.
>
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>  dump/dump.c | 24 ++++++++----------------
>  1 file changed, 8 insertions(+), 16 deletions(-)
>
> diff --git a/dump/dump.c b/dump/dump.c
> index cd11dec0f4..bdff651da4 100644
> --- a/dump/dump.c
> +++ b/dump/dump.c
> @@ -1808,23 +1808,15 @@ static void dump_init(DumpState *s, int fd, bool
> has_format,
>      }
>
>      if (s->dump_info.d_class == ELFCLASS64) {
> -        if (s->shdr_num) {
> -            s->memory_offset = sizeof(Elf64_Ehdr) +
> -                               sizeof(Elf64_Phdr) * s->phdr_num +
> -                               sizeof(Elf64_Shdr) * s->shdr_num +
> s->note_size;
> -        } else {
> -            s->memory_offset = sizeof(Elf64_Ehdr) +
> -                               sizeof(Elf64_Phdr) * s->phdr_num +
> s->note_size;
> -        }
> +        s->memory_offset = sizeof(Elf64_Ehdr) +
> +                           sizeof(Elf64_Phdr) * s->phdr_num +
> +                           sizeof(Elf64_Shdr) * s->shdr_num +
> +                           s->note_size;
>      } else {
> -        if (s->shdr_num) {
> -            s->memory_offset = sizeof(Elf32_Ehdr) +
> -                               sizeof(Elf32_Phdr) * s->phdr_num +
> -                               sizeof(Elf32_Shdr) * s->shdr_num +
> s->note_size;
> -        } else {
> -            s->memory_offset = sizeof(Elf32_Ehdr) +
> -                               sizeof(Elf32_Phdr) * s->phdr_num +
> s->note_size;
> -        }
> +        s->memory_offset = sizeof(Elf32_Ehdr) +
> +                           sizeof(Elf32_Phdr) * s->phdr_num +
> +                           sizeof(Elf32_Shdr) * s->shdr_num +
> +                           s->note_size;
>      }
>
>      return;
> --
> 2.32.0
>
>
>
diff mbox series

Patch

diff --git a/dump/dump.c b/dump/dump.c
index cd11dec0f4..bdff651da4 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -1808,23 +1808,15 @@  static void dump_init(DumpState *s, int fd, bool has_format,
     }
 
     if (s->dump_info.d_class == ELFCLASS64) {
-        if (s->shdr_num) {
-            s->memory_offset = sizeof(Elf64_Ehdr) +
-                               sizeof(Elf64_Phdr) * s->phdr_num +
-                               sizeof(Elf64_Shdr) * s->shdr_num + s->note_size;
-        } else {
-            s->memory_offset = sizeof(Elf64_Ehdr) +
-                               sizeof(Elf64_Phdr) * s->phdr_num + s->note_size;
-        }
+        s->memory_offset = sizeof(Elf64_Ehdr) +
+                           sizeof(Elf64_Phdr) * s->phdr_num +
+                           sizeof(Elf64_Shdr) * s->shdr_num +
+                           s->note_size;
     } else {
-        if (s->shdr_num) {
-            s->memory_offset = sizeof(Elf32_Ehdr) +
-                               sizeof(Elf32_Phdr) * s->phdr_num +
-                               sizeof(Elf32_Shdr) * s->shdr_num + s->note_size;
-        } else {
-            s->memory_offset = sizeof(Elf32_Ehdr) +
-                               sizeof(Elf32_Phdr) * s->phdr_num + s->note_size;
-        }
+        s->memory_offset = sizeof(Elf32_Ehdr) +
+                           sizeof(Elf32_Phdr) * s->phdr_num +
+                           sizeof(Elf32_Shdr) * s->shdr_num +
+                           s->note_size;
     }
 
     return;