ref: bdcd33e06eb729c36cf21ec559556ba6ddaad6a0
parent: cd137ca7a0463d165f29279b89e463c17553b32d
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Sep 8 13:50:53 EDT 2017
[as] Improve isect() xmalloc uses always size_t, so we cannot rely in TUINT and we have to check against SIZE_MAX.
--- 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 @@
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 @@
{
TUINT addr;
- if (pass == 1 || !(sec->flags & SFILE))
+ if (!sec->mem)
return;
for (addr = sec->pc - sec->base; nbytes--; addr++)