From 19336445df1cc012440895bf40dd2df675a8bce8 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Tue, 26 Aug 2008 13:02:54 +0000 Subject: [PATCH] IsElfWii(): return false if open fails. Also query file size only once. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@324 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Core/Src/Boot/Boot_ELF.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/Core/Core/Src/Boot/Boot_ELF.cpp b/Source/Core/Core/Src/Boot/Boot_ELF.cpp index 885c6f727f..4ec7d67b5a 100644 --- a/Source/Core/Core/Src/Boot/Boot_ELF.cpp +++ b/Source/Core/Core/Src/Boot/Boot_ELF.cpp @@ -7,10 +7,12 @@ bool CBoot::IsElfWii(const char *filename) { Common::IMappedFile *mapfile = Common::IMappedFile::CreateMappedFile(); - mapfile->Open(filename); - u8 *ptr = mapfile->Lock(0, mapfile->GetSize()); - u8 *mem = new u8[(size_t)mapfile->GetSize()]; - memcpy(mem, ptr, (size_t)mapfile->GetSize()); + bool ok = mapfile->Open(filename); + if (!ok) return false; + size_t filesize = mapfile->GetSize(); + u8 *ptr = mapfile->Lock(0, filesize); + u8 *mem = new u8[filesize]; + memcpy(mem, ptr, filesize); mapfile->Unlock(ptr); mapfile->Close();