From c2a4d069dcb252fa3ae2d276868e1fc17955e0c3 Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Wed, 13 Sep 2023 22:40:19 -0400 Subject: [PATCH] physfs.hpp: Additional error handling --- src/3rdparty/physfs.hpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/3rdparty/physfs.hpp b/src/3rdparty/physfs.hpp index 3055ebdc4db..2d475c0afb1 100755 --- a/src/3rdparty/physfs.hpp +++ b/src/3rdparty/physfs.hpp @@ -116,16 +116,25 @@ class fbuf : public streambuf { pos_type seekoff(off_type pos, ios_base::seekdir dir, ios_base::openmode mode) { if (dir == std::ios_base::beg) { - PHYSFS_seek(file, pos); + if (PHYSFS_seek(file, pos) == 0) + { + return pos_type(-1); + } } else if (dir == std::ios_base::cur) { // subtract characters currently in buffer from seek position - PHYSFS_seek(file, (PHYSFS_tell(file) + pos) - (egptr() - gptr())); + if (PHYSFS_seek(file, (PHYSFS_tell(file) + pos) - (egptr() - gptr())) == 0) + { + return pos_type(-1); + } } else if (dir == std::ios_base::end) { - PHYSFS_seek(file, PHYSFS_fileLength(file) + pos); + if (PHYSFS_seek(file, PHYSFS_fileLength(file) + pos) == 0) + { + return pos_type(-1); + } } else { @@ -142,7 +151,10 @@ class fbuf : public streambuf { } pos_type seekpos(pos_type pos, std::ios_base::openmode mode) { - PHYSFS_seek(file, pos); + if (PHYSFS_seek(file, pos) == 0) + { + return pos_type(-1); + } if (mode & std::ios_base::in) { setg(egptr(), egptr(), egptr()); }