diff options
author | Cyrill Gorcunov <gorcunov@gmail.com> | 2010-11-10 23:12:06 +0300 |
---|---|---|
committer | Cyrill Gorcunov <gorcunov@gmail.com> | 2010-11-10 23:17:34 +0300 |
commit | 55cc4d04235cb884a885682b5a52f367ec7d50c3 (patch) | |
tree | 52c9cc9d168471ac60fe29f6b6c6bba04c181bad | |
parent | 5fa1b1f47a86512e4e238540342d294c83df2dfe (diff) | |
download | nasm-55cc4d04235cb884a885682b5a52f367ec7d50c3.tar.gz nasm-55cc4d04235cb884a885682b5a52f367ec7d50c3.tar.bz2 nasm-55cc4d04235cb884a885682b5a52f367ec7d50c3.zip |
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>
-rw-r--r-- | preproc.c | 26 |
1 files changed, 12 insertions, 14 deletions
@@ -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); - } } /* |