From 787997a6e90e22537d61f4c155ac0a5bf2018109 Mon Sep 17 00:00:00 2001 From: Jiri Gaisler Date: Tue, 2 Jul 2019 21:06:47 +0200 Subject: elf_load() failed in interactive shell. --- elf.c | 23 ++++++++++------------- sis.h | 2 +- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/elf.c b/elf.c index 2a73ce3..f0240dc 100644 --- a/elf.c +++ b/elf.c @@ -112,7 +112,7 @@ read_elf_body () FILE *fp = efile.fp; fseek (fp, ehdr.e_shoff + ((ehdr.e_shstrndx) * ehdr.e_shentsize), SEEK_SET); - if (fread (&ssh, sizeof (ssh), 1, fp) != 1) + if ((!fp) || (fread (&ssh, sizeof (ssh), 1, fp) != 1)) { return (-1); } @@ -217,26 +217,23 @@ read_elf_body () } int -elf_load (char *fname, int readsym) +elf_load (char *fname, int load) { FILE *fp; int res; - if (!readsym) + if ((fp = fopen (fname, "r")) == NULL) { - if ((fp = fopen (fname, "r")) == NULL) - { - printf ("file not found\n"); - return (-1); - } + printf ("file not found\n"); + return (-1); + } - res = read_elf_header (fp); - if (res < 0) - printf ("File read error\n"); + res = read_elf_header (fp); + if (res < 0) + printf ("File read error\n"); - } - else + if (load && (res >= 0)) { res = read_elf_body (); if (res < 0) diff --git a/sis.h b/sis.h index a15a83f..8ddb6bb 100644 --- a/sis.h +++ b/sis.h @@ -292,7 +292,7 @@ extern int check_wpw (struct pstate *sregs, int32 address, extern void reset_all (void); extern void sys_reset (void); extern void sys_halt (void); -extern int elf_load (char *fname, int readsym); +extern int elf_load (char *fname, int load); extern double get_time (void); extern int nouartrx; //extern host_callback *sim_callback; -- cgit v1.2.3