peter@sugar.UUCP (Peter da Silva) (08/25/87)
The following function, which seems to be an overly complex version
of fgetc(fp), has a serious bug in it. It's from "genv.c" in the Amiga
code for the uupc program.
Basically, line[256] has to be static. I find it hard to believe that
this code was ever tested... because there is no way line[] will remain
valid from invocation to invocation. In addition, the function is
entirely superfluous since it's identical in function to "fgetc()".
/*--------------------------------------------------------------*/
/* getone: get next character file f. f already open */
/*--------------------------------------------------------------*/
static int getone( f )
FILE *f;
{
char c, line[256];
static int pos = 0;
static int len = 0;
if ( ++pos > len || line[pos] == '\0' )
{
if ( fgets( line, 255, f ) == NULL )
return EOF;
pos = 0;
len = strlen( line );
}
c = line[pos];
return c;
}
--
-- Peter da Silva `-_-' ...!seismo!soma!uhnix1!sugar!peter
-- U <--- not a copyrighted cartoon :->mouse@mcgill-vision.UUCP (09/19/87)
In article <563@sugar.UUCP>, peter@sugar.UUCP (Peter da Silva) writes: > The following [...] complex version of fgetc(fp) has a serious bug in > it. It's from "genv.c" in the Amiga code for the uupc program. > Basically, line[256] has to be static. Not only that: even if you do make it static, the function will break badly if called with various different stdio streams, since if there is something in its buffer it *ignores* its argument! But it's all academic because, as you point out, it > ... is entirely superfluous since it's identical in function to > "fgetc()". der Mouse (mouse@mcgill-vision.uucp)