scc

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

commit 7c8e979f1d5f58982cae51893eec769c28b716b3
parent b79fb78e5800e18978ed22288e8ad3bf6702cf0d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 20 Jan 2016 15:53:41 +0100

Check correctness of indexes in designators

This is an error and can generate a segmentation fault if
it is not controlled.

Diffstat:
Mcc1/init.c | 5+++++
1 file changed, 5 insertions(+), 0 deletions(-)

diff --git a/cc1/init.c b/cc1/init.c @@ -31,12 +31,17 @@ arydesig(Init *ip) { TINT npos; Node *np; + Type *tp = ip->type; if (ip->type->op != ARY) errorp("array index in non-array initializer"); next(); np = iconstexpr(); npos = np->sym->u.i; + if (npos < 0 || tp->defined && npos >= tp->n.elem) { + errorp("array index in initializer exceeds array bounds"); + npos = 0; + } freetree(np); expect(']'); return npos;