[hackers] [scc] [cc2] calloc() in nextpc to initialize all fields || Quentin Rameau

From: <git_AT_suckless.org>
Date: Tue, 21 Jun 2016 21:03:01 +0200 (CEST)

commit 92ec299f9e82a1b01725030914fcb48727a3b296
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Tue Jun 21 20:46:58 2016 +0200
Commit: Quentin Rameau <quinq_AT_fifth.space>
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
_AT_@ -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
_AT_@ -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;
 }
 
Received on Tue Jun 21 2016 - 21:03:01 CEST

This archive was generated by hypermail 2.3.0 : Tue Jun 21 2016 - 21:12:22 CEST