ref: 6284570962706a28b1bf7a45a59dad2261b49008
parent: a55a15f4d28510af4023b35ea2301bbbbf5c231a
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Oct 30 01:45:56 EDT 2021
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.
--- 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>
--- 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 @@
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 @@
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 @@
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;