scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 92ec299f9e82a1b01725030914fcb48727a3b296
parent 7d016335501de5c25a3473d342190b7ab2e88283
Author: Quentin Rameau <quinq@fifth.space>
Date:   Tue, 21 Jun 2016 20:46:58 +0200

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

Diffstat:
Mcc2/cc2.h | 2+-
Mcc2/code.c | 6++----
2 files changed, 3 insertions(+), 5 deletions(-)

diff --git 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 @@ -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; }