Fix style issues in elfpatch.c

This commit is contained in:
Mario Hüttel 2023-01-06 20:24:12 +01:00
parent 2c7ce64722
commit b47828014e

View File

@ -62,7 +62,7 @@ struct elfpatch {
#define ret_val_if_ep_err(ep, val) do { \
if (!is_elfpatch_struct((ep))) { \
return (val); \
return val; \
} \
} while (0)
@ -218,9 +218,10 @@ static SlList *elf_patch_get_sections(elfpatch_handle_t *ep)
sec->lma = (uint64_t)sec->section_header.sh_addr;
name = elf_strptr(ep->elf, shstrndx, sec->section_header.sh_name);
if (name) {
if (name)
sec->name = strdup(name);
}
ret = sl_list_append(ret, sec);
}
@ -431,15 +432,13 @@ elfpatch_handle_t *elf_patch_open(const char *path, bool readonly, bool expect_l
switch (ident[5]) {
case 1:
print_debug("ELF Endianess: little\n");
if (!expect_little_endian) {
if (!expect_little_endian)
print_err("Big endian format expected. File is little endian. Double check settings!\n");
}
break;
case 2:
print_debug("ELF Endianess: big\n");
if (expect_little_endian) {
if (expect_little_endian)
print_err("Little endian format expected. File is big endian. Double check settings!\n");
}
break;
default:
print_err("Cannot determine endianess of ELF file. EI_DATA is: %d\n", ident[5]);
@ -454,9 +453,8 @@ close_elf:
ep->elf = NULL;
}
close_fd:
if (ep->fd > 0) {
if (ep->fd > 0)
close(ep->fd);
}
free_struct:
free(ep);
ep = NULL;
@ -561,15 +559,13 @@ int elf_patch_compute_crc_over_section(elfpatch_handle_t *ep, const char *sectio
section, padding_count);
}
for (idx = 0; idx < data->d_size; idx++) {
for (idx = 0; idx < data->d_size; idx++)
crc_push_byte(crc, ((char *)data->d_buf)[translate_index(idx, granularity, little_endian)]);
}
/* Pad with zeroes */
for (idx = 0; idx < padding_count; idx++) {
for (idx = 0; idx < padding_count; idx++)
crc_push_byte(crc, 0x00);
}
}
return 0;
}
@ -711,8 +707,8 @@ int elf_patch_write_crcs_to_section(elfpatch_handle_t *ep, const char *output_se
print_debug("Single CRC requires %u bytes.\n", (unsigned int)crc_size_bytes);
needed_space = calculate_needed_space_for_crcs(format, crc_data->elf_bits, check_start_magic, check_end_magic, crc_size_bytes,
crc_count);
needed_space = calculate_needed_space_for_crcs(format, crc_data->elf_bits, check_start_magic,
check_end_magic, crc_size_bytes, crc_count);
print_debug("Required space for %zu CRCs%s: %zu (available: %zu)\n",
crc_count,
@ -782,12 +778,11 @@ int elf_patch_write_crcs_to_section(elfpatch_handle_t *ep, const char *output_se
crc_64bit.length = 0ull;
crc_64bit.start_address = 0ull;
if (crc_data->elf_bits == 32) {
if (crc_data->elf_bits == 32)
memcpy(sec_bytes, &crc_32bit, sizeof(crc_32bit));
} else {
else
memcpy(sec_bytes, &crc_64bit, sizeof(crc_64bit));
}
}
/* Flag section data as invalid to trigger rewrite.
* This is needed due to the forced memory layout
@ -808,11 +803,10 @@ void elf_patch_close_and_free(elfpatch_handle_t *ep)
if (ep->readonly) {
print_debug("DRY RUN: File will not be updated\n");
} else {
if (elf_update(ep->elf, ELF_C_WRITE) < 0) {
if (elf_update(ep->elf, ELF_C_WRITE) < 0)
print_err("Error writing ELF file: %s\n", elf_errmsg(-1));
}
}
}
if (ep->elf)
elf_end(ep->elf);