some bugs in Vax Tartan C compiler
William L. Sebok
wls at astrovax.UUCP
Sun Jan 27 15:49:11 AEST 1985
The following two programs illustrate two bugs I have found in the Vax Tartan C
compiler (Version CV(bsd)-1.0).
bug #1
-----------------
struct s {
int s1;
int s2;
} st = { 6537, 0 };
int b[] = { 123, 6537, 4567 };
int v = 2;
main() {
if (tstbug(&st))
printf("The bug is present.\n");
}
tstbug(ps)
struct s *ps;
{
int *p;
for(p = b; p < &b[v]; p++) {
if(*p == ps->s1) {
if(ps->s2)
printf("This function call seems necessary\n");
return(0);
}
}
return(1);
}
---------------------
What is happening here is that &b[v] is being evaluated into the same register
(r11) in which ps is kept. Thus the second time around the loop when the
test should have succeeded it is actually comparing *p against
((struct s *)&b[v])->s1 rather than ps->s1.
This bug was originally found in the compilation of function onbill() in the
file hack.shk.c of the source to the game "hack" recently posted to net.sources.
The above mini-program was an attempt to find the smallest program that showed
this bug.
==============================
Bug #2
---------------
short n = 100;
main()
{
if (++n > 100)
n = 200;
if (n == 101)
printf("Bug is present.\n");
}
----------
The test is being compiled into an acbw instruction, which unfortunately
is off by one. It is as if they thought that it would branch on less than
rather than less than or equal to as is the case. If "n" is a char it also
shows this bug. Then the test is compiled into a acbb instruction. However
if n is an int or a long there is no bug. Then the test is compiled into
an aoblss instruction which actually does branch on less than.
This bug was originally found in the compilation of function doinv() in
file hack.invent.c of the source to the game "hack" recently posted to
net.sources. The above mini-program was an attempt to find the smallest
program that showed this bug.
Hack seems to have been an excellent workout for this compiler. Other than
these two things I haven't had any problems so far.
--
Bill Sebok Princeton University, Astrophysics
{allegra,akgua,burl,cbosgd,decvax,ihnp4,noao,princeton,vax135}!astrovax!wls
More information about the Comp.unix.wizards
mailing list