scc

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

commit fdf6db7e69404134489a6f6aa7c8512a69307e6f
parent 000d4104bf2f31750b2699b35a59484179b462ba
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 21 May 2015 12:52:32 +0200

Remove memset in declarator()

Diffstat:
Mcc1/decl.c | 18+++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/cc1/decl.c b/cc1/decl.c @@ -16,18 +16,23 @@ struct dcldata { unsigned char op; unsigned short nelem; + unsigned ndcl; void *data; }; static struct dcldata * queue(struct dcldata *dp, unsigned op, short nelem, void *data) { - if (dp->op == 255) + unsigned n; + + if ((n = dp->ndcl) == NR_DECLARATORS) error("too much declarators"); dp->op = op; dp->nelem = nelem; dp->data = data; - return dp + 1; + ++dp; + dp->ndcl = n+1; + return dp; } static struct dcldata * @@ -139,14 +144,13 @@ declarator0(struct dcldata *dp, unsigned ns) static Symbol * declarator(Type *tp, int flags, unsigned ns) { - struct dcldata data[NR_DECLARATORS+2]; + struct dcldata data[NR_DECLARATORS+1]; struct dcldata *bp; Symbol *sym; - /* TODO: Change this code. The memset is a very bad idea */ - memset(data, 0, sizeof(data)); - data[NR_DECLARATORS].op = 255; - for (bp = declarator0(data, ns)-1; bp >= data; --bp) { + data[0].ndcl = 0; + for (bp = declarator0(data, ns); bp > data; ) { + --bp; if (bp->op != IDEN) { tp = mktype(tp, bp->op, bp->nelem, bp->data); } else {