From 55cc4d04235cb884a885682b5a52f367ec7d50c3 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Wed, 10 Nov 2010 23:12:06 +0300 Subject: [PATCH] preproc: do_directive: Allocate 'Include' from zeroified-memory If not all members of structure being allocated from heap get initialized we better to use nasm_zalloc instead of nasm_malloc. For example inc gets allocated in do_directive being parially initialized and we erroniously get mmac_depth set to some crappy value leading to SIGSEV in result. [ http://forum.nasm.us/index.php?topic=921.msg3257#msg3257 ] nb: I've cleaned verror from tab/space mess while were at it Signed-off-by: Cyrill Gorcunov --- preproc.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/preproc.c b/preproc.c index 8c53cfa8..99b9beb1 100644 --- a/preproc.c +++ b/preproc.c @@ -2601,7 +2601,7 @@ static int do_directive(Token * tline) p = t->text; if (t->type != TOK_INTERNAL_STRING) nasm_unquote_cstr(p, i); - inc = nasm_malloc(sizeof(Include)); + inc = nasm_zalloc(sizeof(Include)); inc->next = istk; inc->fp = inc_fopen(p, dephead, &deptail, pass == 0); if (!inc->fp) { @@ -5019,21 +5019,19 @@ static void verror(int severity, const char *fmt, va_list arg) vsnprintf(buff, sizeof(buff), fmt, arg); - if ((istk != NULL) && (istk->mmac_depth > 0)) { - ExpInv *ei = istk->expansion; - int lineno = ei->lineno; - while (ei != NULL) { - if (ei->type == EXP_MMACRO) { - break; - } - lineno += ei->relno; - ei = ei->prev; - } + if (istk && istk->mmac_depth > 0) { + ExpInv *ei = istk->expansion; + int lineno = ei->lineno; + while (ei) { + if (ei->type == EXP_MMACRO) + break; + lineno += ei->relno; + ei = ei->prev; + } nasm_error(severity, "(%s:%d) %s", ei->def->name, - lineno, buff); - } else { + lineno, buff); + } else nasm_error(severity, "%s", buff); - } } /*