sdo@PURDUE.EDU (Shawn Ostermann) (02/08/89)
(A little trivia for pointer buffs)
I was helping the VM Xinu guys track down a bug, and found a coding
mistake that has been living in a library file for years. The bug is
in the library file src/lib/libxc/doscan.c, and the interesting
parts are as follows (watch the variable fileended):
MANY LINES DELETED
/* doscan.c - doscan */
...
_doscan( ... )
{
int **ptr, fileended, size;
...
fileended = 0;
...
if (_innum(ptr, ch, len, size, getch, ungetch,
arg1, arg2, fileended) && ptr)
...
}
...
_innum(ptr, type, len, size, getch, ungetch, arg1, arg2, eofptr)
...
int *eofptr;
{
...
if (c != EOF) {
(*ungetch)(arg1, arg2);
*eofptr = 0;
} else
*eofptr = 1;
...
}
_innum is trying to use eofptr as a flag for doscan. The mistake (as
you've ALL already seen (-: ) is that the call to innum SHOULD be
if (_innum(ptr, ch, len, size, getch, ungetch,
arg1, arg2, &fileended) && ptr)
^
to pass the ADDRESS of fileended, rather than a null pointer. The bug
was never noticed in the old Xinu stuff because address 0 was writable,
and not used. In VM Xinu, however, that is an illegal address for
some processes, and the dereferencing causes a page fault (that's how
I found it). A little poking around found that this routine has been
included faithfully in all of the architecture distributions that I
looked at. This will probably never affect anyone using the old Xinu
stuff, but if you're a stickler for good pointer grammar, you might
want to fix it.
The moral of the story:
Boy I'm glad that this module was written before I started working on the
Xinu project, that way (for once) it's not my fault!!!
(no pun intended)
Anybody out there in Xinu land wanna own up to it????!!!
Shawn
-----------------------------------------------------------------------------
Shawn Ostermann ARPA: sdo@cs.purdue.edu UUCP: ...!purdue!sdo
-----------------------------------------------------------------------------krr@PURDUE.EDU (02/09/89)
Ha! I just checked the ConcurrenC version of Xinu, and this version is
correct! I just copied and modified the Unix(t) system's doscan, so Xinu's
bug was not propigated.
- Ken Rodemann krr@cs.purdue.edu
{ihnp4, ucbvax, decvax, pur-ee}!purdue!krr
(t) Unix is a five letter word, and is a trademark of AT&T Bell Laboratories.raj@PURDUE.EDU (02/09/89)
>Ha! I just checked the ConcurrenC version of Xinu, and this version is >correct! I just copied and modified the Unix(t) system's doscan, so Xinu's >bug was not propigated. >- Ken Rodemann krr@cs.purdue.edu > {ihnp4, ucbvax, decvax, pur-ee}!purdue!krr >(t) Unix is a five letter word, and is a trademark of AT&T Bell Laboratories. Software reuseabilty is wonderful. Raj