]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
elf-util: reduce variable scope
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 3 Jan 2022 16:55:32 +0000 (01:55 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 3 Jan 2022 19:27:11 +0000 (04:27 +0900)
src/shared/elf-util.c

index 7a62a8088e5f08e728c92605e029939c430d0581..32335f9cdb7ae48b54015b543863e261799e4dad 100644 (file)
@@ -577,7 +577,7 @@ static int parse_elf(int fd, const char *executable, char **ret, JsonVariant **r
                 .package_metadata = &package_metadata,
                 .modules = &modules,
         };
-        const char *elf_architecture = NULL, *elf_type;
+        const char *elf_type;
         GElf_Ehdr elf_header;
         size_t sz = 0;
         int r;
@@ -646,8 +646,7 @@ static int parse_elf(int fd, const char *executable, char **ret, JsonVariant **r
                 return log_warning_errno(r, "Failed to build JSON object: %m");
 
 #if HAVE_DWELF_ELF_E_MACHINE_STRING
-        elf_architecture = sym_dwelf_elf_e_machine_string(elf_header.e_machine);
-#endif
+        const char *elf_architecture = sym_dwelf_elf_e_machine_string(elf_header.e_machine);
         if (elf_architecture) {
                 _cleanup_(json_variant_unrefp) JsonVariant *json_architecture = NULL;
 
@@ -663,6 +662,7 @@ static int parse_elf(int fd, const char *executable, char **ret, JsonVariant **r
                 if (ret)
                         fprintf(c.f, "ELF object binary architecture: %s\n", elf_architecture);
         }
+#endif
 
         /* We always at least have the ELF type, so merge that (and possibly the arch). */
         r = json_variant_merge(&elf_metadata, package_metadata);