From abd069ada3602a1d922672b6f3d74a3e7b44a4a7 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 18 Jan 2021 14:32:19 +0100 Subject: [PATCH] Check return value when calling ReadArray for savestates Just in case we have a 0-byte file or something. --- Source/Core/Core/State.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index 88d5e74a85..d86da80cfe 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -455,11 +455,7 @@ bool ReadHeader(const std::string& filename, StateHeader& header) { Flush(); File::IOFile f(filename, "rb"); - if (!f) - return false; - - f.ReadArray(&header, 1); - return true; + return f.ReadArray(&header, 1); } std::string GetInfoStringOfSlot(int slot, bool translate) @@ -490,15 +486,14 @@ static void LoadFileStateData(const std::string& filename, std::vector& ret_ { Flush(); File::IOFile f(filename, "rb"); - if (!f) + + StateHeader header; + if (!f.ReadArray(&header, 1)) { Core::DisplayMessage("State not found", 2000); return; } - StateHeader header; - f.ReadArray(&header, 1); - if (strncmp(SConfig::GetInstance().GetGameID().c_str(), header.gameID, 6)) { Core::DisplayMessage(fmt::format("State belongs to a different game (ID {})",