commit 92ec299f9e82a1b01725030914fcb48727a3b296
Author:     Quentin Rameau <[email protected]>
AuthorDate: Tue Jun 21 20:46:58 2016 +0200
Commit:     Quentin Rameau <[email protected]>
CommitDate: Tue Jun 21 21:01:38 2016 +0200

    [cc2] calloc() in nextpc to initialize all fields

diff --git a/cc2/cc2.h b/cc2/cc2.h
index 1883d04..83f3f61 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -27,7 +27,7 @@ enum sclass {
        SMEMB     = 'M',
        SCONST    = '#',
        STRING    = '"',
-       SNONE     = 0
+       SNONE     = 0 /* cc2 relies on SNONE being 0 in nextpc() */
 };
 
 enum types {
diff --git a/cc2/code.c b/cc2/code.c
index 722f288..35c4041 100644
--- a/cc2/code.c
+++ b/cc2/code.c
@@ -11,19 +11,17 @@ nextpc(void)
 {
         Inst *new;
 
-        new = malloc(sizeof(*new)); /* TODO: create an arena */
+        new = xcalloc(sizeof(*new)); /* TODO: create an arena */
 
         if (!pc) {
-                new->next = NULL;
                 prog = new;
         } else {
                 new->next = pc->next;
                 pc->next = new;
         }
 
+       /* SNONE being 0, calloc initialized {from1,from2,to}.kind for us */
         new->prev = pc;
-       new->flags = 0;
-        new->to.kind = new->from2.kind = new->from1.kind = SNONE;
         pc = new;
 }
 

Reply via email to