flt: fix crash due to macOS libc++ bug in istream::eof()

Apparently eof() in older versions of libc++ returns true if the last character has just been read, whereas the proper behavior is only to return true when attempting to read past the end of the stream.  Since failbit is reliably set in all cases when reading past the length of the stream, we should only trust the result of eof() if fail() also returns true.
This commit is contained in:
rdb 2019-01-09 22:52:18 +01:00
parent 7d398c9aba
commit 3e5f2cf672

View File

@ -139,13 +139,13 @@ advance(bool ok_eof) {
_datagram = Datagram();
}
if (_in.eof()) {
_state = S_eof;
assert(!flt_error_abort);
return FE_end_of_file;
}
if (_in.fail()) {
if (_in.eof()) {
_state = S_eof;
assert(!flt_error_abort);
return FE_end_of_file;
}
_state = S_error;
assert(!flt_error_abort);
return FE_read_error;
@ -170,13 +170,13 @@ advance(bool ok_eof) {
delete[] buffer;
}
if (_in.eof()) {
_state = S_eof;
assert(!flt_error_abort);
return FE_end_of_file;
}
if (_in.fail()) {
if (_in.eof()) {
_state = S_eof;
assert(!flt_error_abort);
return FE_end_of_file;
}
_state = S_error;
assert(!flt_error_abort);
return FE_read_error;
@ -222,11 +222,11 @@ read_next_header() {
char bytes[header_size];
_in.read(bytes, header_size);
if (_in.eof()) {
_next_error = FE_end_of_file;
return;
} else if (_in.fail()) {
if (_in.fail()) {
if (_in.eof()) {
_next_error = FE_end_of_file;
return;
}
_next_error = FE_read_error;
return;
}