From be1662dd1556151e204fd9db9fda327bb0393ae1 Mon Sep 17 00:00:00 2001 From: George Koehler Date: Wed, 30 Oct 2019 16:53:09 -0400 Subject: [PATCH] Change the optional parameter of n_coerc() to a pointer Fixes https://github.com/davidgiven/ack/issues/188 One call to n_coerc() omits the 6th and last argument. This worked in traditional K&R C, but stops working if we declare n_coerc() with a prototype of all 6 parameters. Change the last parameter to a pointer. Declare n_coerc() with prototype, so it now requires all 6 arguments. Pass NULL when have no iocc_t. This NULL exists only to satisfy the prototype; n_coerc() will not use this NULL. A different fix would declare n_coerc() with 5 parameters and `...`, then use to read the 6th argument when it exists. --- util/ncgg/cgg.y | 4 ++-- util/ncgg/coerc.c | 6 +++--- util/ncgg/coerc.h | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/util/ncgg/cgg.y b/util/ncgg/cgg.y index c648d276c..0c0e16514 100644 --- a/util/ncgg/cgg.y +++ b/util/ncgg/cgg.y @@ -607,7 +607,7 @@ coercdeflist_el {startline = lineno; tokpatlen=0; inithall();} STACK allocates generates YIELDS tokeninstance { checkhall(); - n_coerc(0,0,$4,$5,(struct varinfo *) 0,$7); + n_coerc(0,0,$4,$5,NULL,&$7); freevi($4); freevi($5); } @@ -623,7 +623,7 @@ coercdeflist_el optexpr allocates generates yields { tokpatro[0] = 0; checkhall(); - n_coerc($3,$5,$6,$7,$8); + n_coerc($3,$5,$6,$7,$8,NULL); freevi($6); freevi($7); cursetno = -1; diff --git a/util/ncgg/coerc.c b/util/ncgg/coerc.c index 23b711b22..50265c59e 100644 --- a/util/ncgg/coerc.c +++ b/util/ncgg/coerc.c @@ -208,7 +208,7 @@ set_t unstackset; /*VARARGS5*/ -void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, iocc_t in) +void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, iocc_p inp) { register c3_p c3p; register int i; @@ -236,7 +236,7 @@ void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct vari { NEW(rp, struct varinfo); rp->vi_next = 0; - rp->vi_int[0] = in.in_index; + rp->vi_int[0] = inp->in_index; } if (nallreg > 1) error("More than 1 register may not be allocated"); @@ -250,7 +250,7 @@ void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct vari dopattern(ti == 0, VI_NULL, al, ge, rp, VI_NULL); if (ti == 0) for (i = 0; i < SETSIZE; i++) - unstackset.set_val[i] |= in.in_set[i]; + unstackset.set_val[i] |= inp->in_set[i]; freevi(rp); } diff --git a/util/ncgg/coerc.h b/util/ncgg/coerc.h index b34338e2f..e45c75754 100644 --- a/util/ncgg/coerc.h +++ b/util/ncgg/coerc.h @@ -23,8 +23,7 @@ struct varinfo *gen_preturn(void); struct varinfo *gen_tlab(int n); void n_stack(int s, int e, int p, struct varinfo *vi); void checkstacking(register short *sp); -/* cgg.y is buggy!!! it has one less parameter.. */ -/*void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, iocc_t in);*/ +void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, iocc_p inp); void checkunstacking(int setno); #endif /* COERC_H_ */