scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 7733e0ee7a75596ddeba68d6296e6ac4d23e18ad
parent 1f350b8f200581b66c4a5fc2dd74ee2fbf574c4a
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 23 Oct 2023 10:50:15 +0200

libmach/coff32: Improve file error checking

The check for file operations done in the input file pointer
wa done in two different places and it could miss some errors.
In the same way, the section file pointers were not checked
against errors.

Diffstat:
Msrc/libmach/coff32/coff32write.c | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/libmach/coff32/coff32write.c b/src/libmach/coff32/coff32write.c @@ -216,7 +216,7 @@ writestr(Obj *obj, FILE *fp) fwrite(buf, 4, 1, fp); fwrite(coff->strtbl, coff->strsiz, 1, fp); - return ferror(fp) == 0; + return 1; } static int @@ -317,9 +317,12 @@ writedata(Obj *obj, Map *map, FILE *fp) for (n = sec->end - sec->begin; n > 0; n--) putc(getc(sec->fp), fp); + + if (ferror(sec->fp)) + return 0; } - return !ferror(fp); + return 1; } int @@ -370,6 +373,8 @@ coff32write(Obj *obj, Map *map, FILE *fp) return -1; if (!writestr(obj, fp)) return -1; + if (ferror(fp)) + return -1; return 0; }