From 5454f57dd048001a0f3c8caddd502caf6089effb Mon Sep 17 00:00:00 2001 From: Megamouse Date: Mon, 4 Jun 2018 11:30:39 +0200 Subject: [PATCH] cellSaveData: handle fatal error fs::file is_null (read-only files) --- rpcs3/Emu/Cell/Modules/cellSaveData.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp index 58e925960c..7b57992379 100644 --- a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp @@ -783,6 +783,11 @@ static NEVER_INLINE s32 savedata_op(ppu_thread& ppu, u32 operation, u32 version, case CELL_SAVEDATA_FILEOP_WRITE: { fs::file file(dir_path + file_path, fs::write + fs::create); + if (!file) + { + fmt::throw_exception("Failed to open file. The file might be read-only: %s%s" HERE, dir_path, file_path); + } + file.seek(fileSet->fileOffset); const auto start = static_cast(fileSet->fileBuf.get_ptr()); std::vector buf(start, start + std::min(fileSet->fileSize, fileSet->fileBufSize)); @@ -801,6 +806,11 @@ static NEVER_INLINE s32 savedata_op(ppu_thread& ppu, u32 operation, u32 version, case CELL_SAVEDATA_FILEOP_WRITE_NOTRUNC: { fs::file file(dir_path + file_path, fs::write + fs::create); + if (!file) + { + fmt::throw_exception("Failed to open file. The file might be read-only: %s%s" HERE, dir_path, file_path); + } + file.seek(fileSet->fileOffset); const auto start = static_cast(fileSet->fileBuf.get_ptr()); std::vector buf(start, start + std::min(fileSet->fileSize, fileSet->fileBufSize));