소스 검색

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.
rdb 7 년 전
부모
커밋
3e5f2cf672
1개의 변경된 파일17개의 추가작업 그리고 17개의 파일을 삭제
  1. 17 17
      pandatool/src/flt/fltRecordReader.cxx

+ 17 - 17
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;
   }