[net.sources.bugs] some bugs in vc spreadsheet calculator

royr@basser.oz (Roy Rankin) (01/14/85)

I have found a serious bug for anyone  trying to run the vc
spreadsheet on a machine which has a different size for int
and long.

In the YACC grammer file gram.y the type of ival
should agree with the default type of function arguments and
return values, i.e. int, not long. The easiest fix is as follows:

In line 17 of gram.y  change
17,17
<        long ival;
---
>        int ival;


To allow vc to then correctly process large integers the following
change must then be made to lex.c:

70,71c70,80
<           ret = NUMBER;
<           yylval.ival = v;
---
>           if((int)v != v)
>           {
>               ret = FNUMBER;
>               yylval.fval = v;
>           }
>           else
>           {
>
>               ret = NUMBER;
>               yylval.ival = v;
>           }

In addition to the above bug, the following line of code wasted
considerable memory, which was untolerable on my PDP11/34,
particularly since the amount of memory needed is easily found
as shown in the following modification to lex.c.

76c85,87
<       ptr = (char *)malloc(256);
---
>       ptr = p+1;
>       while(*ptr && *ptr++ != '"');
>       ptr = (char *)malloc((unsigned)(ptr-p));

Finally, I would recommend that all calls to malloc in the program be
replaced with a call to a function which calls malloc and checks
that the program has not run out of memory.  In so doing,
I discovered that some strange program behavior was a result
of the program  running out of memory.

Roy Rankin		decvax!mulga!mhd!roy
School of Electrical Enginnering
University of Sydney
Sydney, Australia 2006