scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 1a8979366fae2352f66712363b1d49f4bd3c9a10
parent 978a8ca13e0a40616ed5525663653d82efaa8eb4
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 24 Oct 2022 17:47:00 +0200

cc1: Avoid undefined behaviour

A compound literal has a timelife limited to the scope where it
is defined and in this case the object was accessed out of its
timelife.

Diffstat:
Msrc/cmd/cc/cc1/decl.c | 3++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/cmd/cc/cc1/decl.c b/src/cmd/cc/cc1/decl.c @@ -494,6 +494,7 @@ funbody(Symbol *sym, Symbol *pars[]) { Type *tp; Symbol **bp, *p; + Symbol *emptypars[] = {NULL}; if (!sym) return 0; @@ -510,7 +511,7 @@ funbody(Symbol *sym, Symbol *pars[]) assert(!pars); errorp("typedef'ed function type cannot be instantiated"); curctx = PARAMCTX; - pars = (Symbol *[]) {NULL}; + pars = emptypars; } if (curctx != PARAMCTX)