new bug in fgetc_unlocked ?
Pascal Terjan <[email protected]>
| Newsgroups | gmane.linux.lib.dietlibc |
|---|---|
| Organization | Mandriva |
| Message-ID | <1234453696.1318.66.camel@plop> |
Hello
In recent snapshots, reading of terminfo data in Mandriva installer is
broken, fread returns less bytes than it should while the file is not
finished.
While investigating this, I ended up in fgetc_unlocked
Commenting the 2 following lines fixes my bug but I don't understand
why :
if (__likely(stream->bm<stream->bs))
return stream->buf[stream->bm++];
There is however something that look very strange then:
if (__fflush4(stream,BUFINPUT)) return EOF;
if (__unlikely(stream->bm>=stream->bs)) {
__fflush4 will ensure that stream->bm == stream->bs == 0, so __unlikely
is strange, and actually I think that full test is useless.
Why not doing something like the following :
if (__unlikely(stream->bm>=stream->bs)) {
if (__unlikely(feof_unlocked(stream)))
return EOF;
if (__fflush4(stream,BUFINPUT)) return EOF;
ssize_t len=__libc_read(stream->fd,stream->buf,stream->buflen);
if (len==0) {
stream->flags|=EOFINDICATOR;
return EOF;
} else if (len<0) {
kaputt:
stream->flags|=ERRORINDICATOR;
return EOF;
}
stream->bm=0;
stream->bs=len;
}
c=stream->buf[stream->bm];
++stream->bm;
return c;