Skip to content

Commit

Permalink
rimage: elf: fixed error handling from file operation
Browse files Browse the repository at this point in the history
Fixes error handling

Signed-off-by: Adrian Bonislawski <[email protected]>
  • Loading branch information
abonislawski committed Nov 28, 2023
1 parent 84ed076 commit a1f24c7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tools/rimage/src/elf_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static int elf_header_read(struct elf_file *elf)
/* read in elf header */
count = fread(&elf->header, sizeof(elf->header), 1, elf->file);
if (count != 1) {
if (count < 0)
if (!count)
return file_error("failed to read elf header", elf->filename);
else
return elf_error(elf, "Corrupted file.", ENODATA);
Expand Down Expand Up @@ -199,7 +199,7 @@ static int elf_section_headers_read(struct elf_file *elf)

count = fread(&elf->sections[i].data, sizeof(Elf32_Shdr), 1, elf->file);
if (count != 1) {
if (count < 0)
if (!count)
return file_error("failed to read section header", elf->filename);
else
return elf_error(elf, "Corrupted file.", ENODATA);
Expand Down Expand Up @@ -264,7 +264,7 @@ static int elf_program_headers_read(struct elf_file *elf)

count = fread(&elf->programs[i], sizeof(Elf32_Phdr), 1, elf->file);
if (count != 1) {
if (count < 0)
if (!count)
return file_error("failed to read program header", elf->filename);
else
return elf_error(elf, "Corrupted file.", ENODATA);
Expand Down Expand Up @@ -467,7 +467,7 @@ int elf_section_read_content(const struct elf_file *elf, const struct elf_sectio

count = fread(buffer, header->data.size, 1, elf->file);
if (count != 1) {
if (count < 0)
if (!count)
return file_error("failed to read section data", elf->filename);
else
return elf_error(elf, "Corrupted file.", ENODATA);
Expand Down

0 comments on commit a1f24c7

Please sign in to comment.