shithub: scc

Download patch

ref: 905c84e75d0ccd5a2d92e0313dc20bf35054e902
parent: aadf75311d17eec964fb6a8d1bad898e0920b101
author: Quentin Rameau <quinq@fifth.space>
date: Tue Jun 21 16:46:58 EDT 2016

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

--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -27,7 +27,7 @@
 	SMEMB     = 'M',
 	SCONST    = '#',
 	STRING    = '"',
-	SNONE     = 0
+	SNONE     = 0 /* cc2 relies on SNONE being 0 in nextpc() */
 };
 
 enum types {
--- a/cc2/code.c
+++ b/cc2/code.c
@@ -11,10 +11,9 @@
 {
         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;
@@ -21,9 +20,8 @@
                 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;
 }