This is the mail archive of the guile@cygnus.com mailing list for the guile project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
I see the latest anoncvs source tree has (in genio.c):
char *
scm_do_read_line (port, len)
SCM port;
int *len;
{
char *s;
scm_sizet i;
i = SCM_PTOBNUM (port);
SCM_SYSCALL (s = (scm_ptobs[i].fgets) (port, len));
/* If we're not at EOF, and there was a newline at the end of the
string, increment the line counter. */
if (s && *len > 0 && s[*len - 1] == '\n')
SCM_INCLINE(port);
return s;
}
If the *len > 0 is necessary then scm_read_line (in ioext.c) has a
bug in:
s = scm_do_read_line (port, &slen);
if (s == NULL)
term = line = SCM_EOF_VAL;
else
{
if (s[slen-1] == '\n')
{
term = SCM_MAKICHR ('\n');
line = scm_makfromstr (s, slen-1, 0);
}
else
{
/* Fix: we should check for eof on the port before assuming this. */
term = SCM_EOF_VAL;
line = scm_makfromstr (s, slen, 0);
}
free (s);
}
i.e. - the code in ioext.c implies that if scm_do_read_line, & hence
scm_ptobs[i].fgets doesn't return null then length is >0, which makes
sense.
In other words, there're 2 cases:
1. fgets reads a character - then it's in the returned string & len>0.
2. fgets doesn't read a character - then it returns null.
I could see why you'd want the extra insurance test, but I'd be afraid
of making the code self-inconsistent. Someone might reason about
what fgets can or should return based on the code in genio.c & then
break the code in ioext.c, or might decide there's a bug in ioext.c &
add the additional test, ...
Or do you have other reasons for the extra test?
--
Harvey J. Stein
BFM Financial Research
hjstein@bfr.co.il