scc

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

commit a175b3caf5123f49cca0593c4be90f882451ad65
parent 9e95fc16a44446b7a6ec958a0f92ebda68715e25
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 30 Oct 2021 05:45:56 +0200

libmach/coff32: Remove use of errno to signal errors

The C99 set of values for errno is very limited, being restricted
to a few values. Since the user cannot portably define its own values
trying to use errno to signal user errors is kind of impossible in
a C99 program.

Diffstat:
Msrc/libmach/coff32/coff32getsym.c | 1-
Msrc/libmach/coff32/coff32read.c | 13+++----------
2 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/src/libmach/coff32/coff32getsym.c b/src/libmach/coff32/coff32getsym.c @@ -1,5 +1,4 @@ #include <ctype.h> -#include <errno.h> #include <stdio.h> #include <scc/mach.h> diff --git a/src/libmach/coff32/coff32read.c b/src/libmach/coff32/coff32read.c @@ -1,6 +1,5 @@ #include <assert.h> #include <ctype.h> -#include <errno.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> @@ -157,10 +156,8 @@ readstr(Obj *obj, FILE *fp) if (fread(buf, 4, 1, fp) != 1) return 0; unpack(ORDER(obj->type), buf, "l", &siz); - if (siz < 4 || siz > SIZE_MAX) { - errno = ERANGE; + if (siz < 4 || siz > SIZE_MAX) return 0; - } if (siz == 4) return 1; @@ -211,10 +208,8 @@ readreloc(Obj *obj, FILE *fp) if (fread(buf, RELSZ, 1, fp) != 1) return 0; unpack_reloc(ORDER(obj->type), buf, &rp[i]); - if (rp[i].r_symndx >= hdr->f_nsyms) { - errno = ERANGE; + if (rp[i].r_symndx >= hdr->f_nsyms) return 0; - } } } @@ -370,10 +365,8 @@ coff32read(Obj *obj, FILE *fp) for (i = 0; i < hdr->f_nsyms; i++) { SYMENT *ent = &coff->ents[i]; - if (ent->n_zeroes != 0 && ent->n_offset > coff->strsiz) { - errno = ERANGE; + if (ent->n_zeroes != 0 && ent->n_offset > coff->strsiz) return -1; - } } return 0;