Skip to content

Commit 505268c

Browse files
abonislawskikv2019i
authored andcommitted
rimage: elf: fixed error handling from file operation
Fixes error handling Signed-off-by: Adrian Bonislawski <adrian.bonislawski@intel.com> (cherry picked from commit fd61ed6) Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 0bcaaa7 commit 505268c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

tools/rimage/src/elf_file.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static int elf_header_read(struct elf_file *elf)
117117
/* read in elf header */
118118
count = fread(&elf->header, sizeof(elf->header), 1, elf->file);
119119
if (count != 1) {
120-
if (count < 0)
120+
if (!count)
121121
return file_error("failed to read elf header", elf->filename);
122122
else
123123
return elf_error(elf, "Corrupted file.", ENODATA);
@@ -199,7 +199,7 @@ static int elf_section_headers_read(struct elf_file *elf)
199199

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

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

468468
count = fread(buffer, header->data.size, 1, elf->file);
469469
if (count != 1) {
470-
if (count < 0)
470+
if (!count)
471471
return file_error("failed to read section data", elf->filename);
472472
else
473473
return elf_error(elf, "Corrupted file.", ENODATA);

0 commit comments

Comments
 (0)