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 <stdarg.h> to read the 6th argument when it exists.
This commit is contained in:
George Koehler 2019-10-30 16:53:09 -04:00
parent 7ab4794a05
commit be1662dd15
3 changed files with 6 additions and 7 deletions

View file

@ -607,7 +607,7 @@ coercdeflist_el
{startline = lineno; tokpatlen=0; inithall();} {startline = lineno; tokpatlen=0; inithall();}
STACK allocates generates YIELDS tokeninstance STACK allocates generates YIELDS tokeninstance
{ checkhall(); { checkhall();
n_coerc(0,0,$4,$5,(struct varinfo *) 0,$7); n_coerc(0,0,$4,$5,NULL,&$7);
freevi($4); freevi($4);
freevi($5); freevi($5);
} }
@ -623,7 +623,7 @@ coercdeflist_el
optexpr allocates generates yields optexpr allocates generates yields
{ tokpatro[0] = 0; { tokpatro[0] = 0;
checkhall(); checkhall();
n_coerc($3,$5,$6,$7,$8); n_coerc($3,$5,$6,$7,$8,NULL);
freevi($6); freevi($6);
freevi($7); freevi($7);
cursetno = -1; cursetno = -1;

View file

@ -208,7 +208,7 @@ set_t unstackset;
/*VARARGS5*/ /*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 c3_p c3p;
register int i; 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); NEW(rp, struct varinfo);
rp->vi_next = 0; rp->vi_next = 0;
rp->vi_int[0] = in.in_index; rp->vi_int[0] = inp->in_index;
} }
if (nallreg > 1) if (nallreg > 1)
error("More than 1 register may not be allocated"); 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); dopattern(ti == 0, VI_NULL, al, ge, rp, VI_NULL);
if (ti == 0) if (ti == 0)
for (i = 0; i < SETSIZE; i++) for (i = 0; i < SETSIZE; i++)
unstackset.set_val[i] |= in.in_set[i]; unstackset.set_val[i] |= inp->in_set[i];
freevi(rp); freevi(rp);
} }

View file

@ -23,8 +23,7 @@ struct varinfo *gen_preturn(void);
struct varinfo *gen_tlab(int n); struct varinfo *gen_tlab(int n);
void n_stack(int s, int e, int p, struct varinfo *vi); void n_stack(int s, int e, int p, struct varinfo *vi);
void checkstacking(register short *sp); 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_p inp);
/*void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, iocc_t in);*/
void checkunstacking(int setno); void checkunstacking(int setno);
#endif /* COERC_H_ */ #endif /* COERC_H_ */