preproc: do_directive: Allocate 'Include' from zeroified-memory
authorCyrill Gorcunov <gorcunov@gmail.com>
Wed, 10 Nov 2010 20:12:06 +0000 (23:12 +0300)
committerCyrill Gorcunov <gorcunov@gmail.com>
Wed, 10 Nov 2010 20:17:34 +0000 (23:17 +0300)
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>
preproc.c

index 8c53cfa..99b9beb 100644 (file)
--- 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);
-       }
 }
 
 /*