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 <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov 2010-11-10 23:12:06 +03:00
parent 5fa1b1f47a
commit 55cc4d0423

View File

@ -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);
}
}
/*