scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 4d8c8842d85ac73f572a5cd009df21d042f052a4
parent 79e21860ac133bb98f1dcf5a1ecf22759e6e0e26
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri,  8 Sep 2017 17:50:53 +0200

[as] Improve isect()

xmalloc uses always size_t, so we cannot rely in TUINT
and we have to check against SIZE_MAX.

Diffstat:
as/emit.c | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/as/emit.c b/as/emit.c @@ -1,5 +1,6 @@ #include <stdio.h> +#include <stdint.h> #include <string.h> #include "../inc/scc.h" @@ -15,9 +16,16 @@ int pass; static void isec(Section *sec) { + TUINT siz; + sec->curpc = sec->pc = sec->base; - if (sec->max > 0) - sec->mem = xmalloc(sec->max - sec->base); + if (pass == 1 || sec->flags & SFILE) + return; + + siz = sec->max - sec->base; + if (siz > SIZE_MAX) + die("out of memory"); + sec->mem = xmalloc(sec->max - sec->base); } void @@ -33,7 +41,7 @@ emit(Section *sec, char *bytes, int nbytes) { TUINT addr; - if (pass == 1 || !(sec->flags & SFILE)) + if (!sec->mem) return; for (addr = sec->pc - sec->base; nbytes--; addr++)