[comp.bugs.misc] Bug in dc? and another one?

wescott@sauron.Columbia.NCR.COM (Mike Wescott) (10/07/87)

In article <1800@ncr-sd.SanDiego.NCR.COM> randall@ncr-sd.SanDiego.NCR.COM (0000-Randall Rathbun) writes:
> Running the short dc routine below to find the gcd of two numbers
> appears to work for small numbers.
> 
> ........
> 
> When r & s are about 100 digits or so in length, an error message appears:
> %Segmentation fault (core dumped)
> 
> What is wrong?

Looks like an overflow of readstk.  readstk has a hard coded limit of 100
in the SysVr3 source that I have access to.  It's a bug in that the exceeding
the limit is not gracefully handled.

While tracking down this problem I came across some strange looking code:

   In readc():
		if((readptr != &readstk[0]) && (*readptr != 0)){
			.
			.
			.
		}
		.
		.
		if(readptr != &readptr[0]){	<===== ???????????
			readptr--;
			.
			.
			.

Surely the author meant  "if(readptr != &readstk[0]) ...

In anycase the whole if stmt gets optimized to nothing.  Looks like the
relics of an attempt to put a more general file reading mechanism into dc.

	-Mike Wescott
-- 
	-Mike Wescott
	 wescott@ncrcae.Columbia.NCR.COM