scc

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

commit 0b90a3871919aa0ecc04b30e174d55fe9c692c9d
parent b2b440217796f450751690e4fb414c0eb53fc2a0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 29 Aug 2019 21:12:45 +0100

[libmach] Allocate string table always

Allocate string table always, even  when it is empty.
This make the code more orthogonal and avoid errors.

Diffstat:
Msrc/libmach/coff32/coff32read.c | 23+++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/src/libmach/coff32/coff32read.c b/src/libmach/coff32/coff32read.c @@ -155,22 +155,17 @@ readstr(Obj *obj, FILE *fp) return 0; unpack(ORDER(obj->type), buf, "l", &siz); coff->strsiz = 0; - if (siz == 4) + if (siz < 4 || siz > SIZE_MAX) { + errno = ERANGE; return 1; - if (siz > 4) { - if (siz > SIZE_MAX) { - errno = ERANGE; - return 0; - } - if ((str = malloc(siz)) == NULL) - return 0; - coff->strtbl = str; - coff->strsiz = siz; - - if (fread(str+4, siz-4, 1, fp) != 1) - return 0; } - return 1; + + if ((str = malloc(siz)) == NULL) + return 0; + coff->strtbl = str; + coff->strsiz = siz; + + return fread(str+4, siz-4, 1, fp) != 1; } static int