From 3e5f2cf67215adf36d4b7fc26098f84483f9e967 Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 9 Jan 2019 22:52:18 +0100 Subject: [PATCH] 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. --- pandatool/src/flt/fltRecordReader.cxx | 34 +++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/pandatool/src/flt/fltRecordReader.cxx b/pandatool/src/flt/fltRecordReader.cxx index 4f1ccfe1bb..eb3ba94840 100644 --- a/pandatool/src/flt/fltRecordReader.cxx +++ b/pandatool/src/flt/fltRecordReader.cxx @@ -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; }