From cf0e337b27735997551e3dcdf455c27462abbcac Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 11:56:19 -0800 Subject: [PATCH 01/22] Fix a memleak on an error condition. --- Common/ChunkFile.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Common/ChunkFile.cpp b/Common/ChunkFile.cpp index 82ad8dd3ab..284e774562 100644 --- a/Common/ChunkFile.cpp +++ b/Common/ChunkFile.cpp @@ -212,6 +212,7 @@ CChunkFileReader::Error CChunkFileReader::LoadFile(const std::string& _rFilename if (!pFile.ReadBytes(buffer, sz)) { ERROR_LOG(COMMON, "ChunkReader: Error reading file"); + delete [] buffer; return ERROR_BAD_FILE; } From ff59cd6e113bd7ad5b9bb09af495c197348521a8 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 11:56:44 -0800 Subject: [PATCH 02/22] Fix a potential debug buffer overrun. --- Core/Debugger/SymbolMap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/Debugger/SymbolMap.cpp b/Core/Debugger/SymbolMap.cpp index 7ce894c4e4..c729e149b0 100644 --- a/Core/Debugger/SymbolMap.cpp +++ b/Core/Debugger/SymbolMap.cpp @@ -788,7 +788,7 @@ void SymbolMap::SetLabelName(const char* name, u32 address) { auto symbolKey = std::make_pair(labelInfo->second.module, labelInfo->second.addr); auto label = labels.find(symbolKey); if (label != labels.end()) { - strcpy(label->second.name,name); + strncpy(label->second.name, name, 128); label->second.name[127] = 0; // Refresh the active item if it exists. From 795088001cd19fca5af89724ebb0703827670a90 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 11:57:07 -0800 Subject: [PATCH 03/22] Avoid passing a GPUstate by value. Only used by Qt GE debugger thing anyway. --- GPU/Directx9/GPU_DX9.h | 2 +- GPU/Directx9/TextureCacheDX9.cpp | 2 +- GPU/Directx9/TextureCacheDX9.h | 2 +- GPU/GLES/GLES_GPU.h | 2 +- GPU/GLES/TextureCache.cpp | 2 +- GPU/GLES/TextureCache.h | 2 +- GPU/GPUCommon.h | 2 +- GPU/GPUInterface.h | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/GPU/Directx9/GPU_DX9.h b/GPU/Directx9/GPU_DX9.h index 519656f80f..37527f0d8d 100644 --- a/GPU/Directx9/GPU_DX9.h +++ b/GPU/Directx9/GPU_DX9.h @@ -60,7 +60,7 @@ public: // Called by the window system if the window size changed. This will be reflected in PSPCoreParam.pixel*. virtual void Resized(); virtual void ClearShaderCache(); - virtual bool DecodeTexture(u8* dest, GPUgstate state) { + virtual bool DecodeTexture(u8 *dest, const GPUgstate &state) { return textureCache_.DecodeTexture(dest, state); } virtual bool FramebufferDirty(); diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index aa3cfe57bf..861a3858ba 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -1738,7 +1738,7 @@ void TextureCacheDX9::LoadTextureLevel(TexCacheEntry &entry, int level, int maxL entry.texture->UnlockRect(level); } -bool TextureCacheDX9::DecodeTexture(u8* output, GPUgstate state) +bool TextureCacheDX9::DecodeTexture(u8 *output, const GPUgstate &state) { OutputDebugStringA("TextureCache::DecodeTexture : FixMe\r\n"); return true; diff --git a/GPU/Directx9/TextureCacheDX9.h b/GPU/Directx9/TextureCacheDX9.h index ba05afa277..cac576b0f3 100644 --- a/GPU/Directx9/TextureCacheDX9.h +++ b/GPU/Directx9/TextureCacheDX9.h @@ -78,7 +78,7 @@ public: } // Only used by Qt UI? - bool DecodeTexture(u8 *output, GPUgstate state); + bool DecodeTexture(u8 *output, const GPUgstate &state); void ForgetLastTexture(); diff --git a/GPU/GLES/GLES_GPU.h b/GPU/GLES/GLES_GPU.h index 472bc93d61..c9937951b1 100644 --- a/GPU/GLES/GLES_GPU.h +++ b/GPU/GLES/GLES_GPU.h @@ -62,7 +62,7 @@ public: virtual void Resized(); virtual void ClearShaderCache(); virtual void CleanupBeforeUI(); - virtual bool DecodeTexture(u8* dest, GPUgstate state) { + virtual bool DecodeTexture(u8 *dest, const GPUgstate &state) { return textureCache_.DecodeTexture(dest, state); } virtual bool FramebufferDirty(); diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index 981bff06a4..7e9d3e4c63 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -2037,7 +2037,7 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, int level, bool replac } // Only used by Qt UI? -bool TextureCache::DecodeTexture(u8* output, GPUgstate state) { +bool TextureCache::DecodeTexture(u8* output, const GPUgstate &state) { GPUgstate oldState = gstate; gstate = state; diff --git a/GPU/GLES/TextureCache.h b/GPU/GLES/TextureCache.h index 87f6b377cf..c4bb20781b 100644 --- a/GPU/GLES/TextureCache.h +++ b/GPU/GLES/TextureCache.h @@ -95,7 +95,7 @@ public: u32 AllocTextureName(); // Only used by Qt UI? - bool DecodeTexture(u8 *output, GPUgstate state); + bool DecodeTexture(u8 *output, const GPUgstate &state); // Wow this is starting to grow big. Soon need to start looking at resizing it. // Must stay a POD. diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index ca3715b445..ab0967b5be 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -111,7 +111,7 @@ public: const std::list& GetDisplayLists() { return dlQueue; } - virtual bool DecodeTexture(u8* dest, GPUgstate state) { + virtual bool DecodeTexture(u8* dest, const GPUgstate &state) { return false; } std::vector GetFramebufferList() { diff --git a/GPU/GPUInterface.h b/GPU/GPUInterface.h index e85030b67f..d10c6ceafc 100644 --- a/GPU/GPUInterface.h +++ b/GPU/GPUInterface.h @@ -284,6 +284,6 @@ public: virtual void DumpNextFrame() = 0; virtual void GetReportingInfo(std::string &primaryInfo, std::string &fullInfo) = 0; virtual const std::list& GetDisplayLists() = 0; - virtual bool DecodeTexture(u8* dest, GPUgstate state) = 0; + virtual bool DecodeTexture(u8* dest, const GPUgstate &state) = 0; virtual std::vector GetFramebufferList() = 0; }; From c0a04cbf7ebb2b56b4432b5e0885b8aefe8e78db Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 11:57:59 -0800 Subject: [PATCH 04/22] armjit: Fix first temp vreg offset. Wonder what havoc this could've caused.... --- Core/MIPS/ARM/ArmRegCacheFPU.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/MIPS/ARM/ArmRegCacheFPU.cpp b/Core/MIPS/ARM/ArmRegCacheFPU.cpp index 2d883945c7..494c06f67b 100644 --- a/Core/MIPS/ARM/ArmRegCacheFPU.cpp +++ b/Core/MIPS/ARM/ArmRegCacheFPU.cpp @@ -572,7 +572,7 @@ int ArmRegCacheFPU::GetMipsRegOffset(MIPSReg r) { return 0; // or what? } - if (r < 32 || r > 32 + 128) { + if (r < 32 || r >= 32 + 128) { return (32 + r) << 2; } else { // r is between 32 and 128 + 32 From 0dc3e4e2db904750b73d9d25968f9fe449330262 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 11:58:36 -0800 Subject: [PATCH 05/22] x86jit: Handle unable to spill better. Might as well check the result to be safe. --- Core/MIPS/x86/RegCacheFPU.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Core/MIPS/x86/RegCacheFPU.cpp b/Core/MIPS/x86/RegCacheFPU.cpp index f7a3229926..c3aa9e20d4 100644 --- a/Core/MIPS/x86/RegCacheFPU.cpp +++ b/Core/MIPS/x86/RegCacheFPU.cpp @@ -242,9 +242,13 @@ bool FPURegCache::TryMapRegsVS(const u8 *v, VectorSize vsz, int flags) { // Single is easy, just map normally but track as a SIMD reg. // This way V/VS can warn about improper usage properly. MapRegV(v[0], flags); + X64Reg vx = VX(v[0]); + if (vx == INVALID_REG) + return false; + vregs[v[0]].lane = 1; if ((flags & MAP_DIRTY) != 0) - xregs[VSX(v)].dirty = true; + xregs[vx].dirty = true; if ((flags & MAP_NOLOCK) == 0) SpillLockV(v, vsz); Invariant(); From 86ec5114d2595284cdb0d7f8e24858f693284c08 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 11:59:07 -0800 Subject: [PATCH 06/22] Fix a bad sprintf() format. --- Windows/W32Util/Misc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Windows/W32Util/Misc.cpp b/Windows/W32Util/Misc.cpp index fce663c804..e1c214c05f 100644 --- a/Windows/W32Util/Misc.cpp +++ b/Windows/W32Util/Misc.cpp @@ -55,9 +55,9 @@ namespace W32Util } float f = (float)size + ((float)frac / 1024.0f); if (s==0) - sprintf(out,"%d B",size); + sprintf(out, "%d B", (int)size); else - sprintf(out,"%3.1f %s",f,sizes[s]); + sprintf(out, "%3.1f %s", f, sizes[s]); } BOOL CopyTextToClipboard(HWND hwnd, const char *text) { From a191b9ac7f238e9d13f3bd33e81cfbb96090bed7 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 12:08:19 -0800 Subject: [PATCH 07/22] Fix a potentially not null terminated string. --- Core/Debugger/SymbolMap.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/Debugger/SymbolMap.cpp b/Core/Debugger/SymbolMap.cpp index c729e149b0..fc9a7b84c8 100644 --- a/Core/Debugger/SymbolMap.cpp +++ b/Core/Debugger/SymbolMap.cpp @@ -426,6 +426,7 @@ void SymbolMap::AddModule(const char *name, u32 address, u32 size) { ModuleEntry mod; strncpy(mod.name, name, ARRAY_SIZE(mod.name)); + mod.name[ARRAY_SIZE(mod.name) - 1] = '\0'; mod.start = address; mod.size = size; mod.index = (int)modules.size() + 1; From d497bc7c8c3b27b131184f16d45816261275c678 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 12:08:39 -0800 Subject: [PATCH 08/22] Ensure safe zim access regardless of file contents. --- Core/Util/PPGeDraw.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Core/Util/PPGeDraw.cpp b/Core/Util/PPGeDraw.cpp index d7e8f65157..2e1e491e24 100644 --- a/Core/Util/PPGeDraw.cpp +++ b/Core/Util/PPGeDraw.cpp @@ -164,19 +164,19 @@ void __PPGeInit() NOTICE_LOG(SCEGE, "Not initializing PPGe - GPU is NullGpu"); return; } - u8 *imageData; - int width; - int height; + u8 *imageData[12]; + int width[12]; + int height[12]; int flags; - if (!LoadZIM("ppge_atlas.zim", &width, &height, &flags, &imageData)) { + if (!LoadZIM("ppge_atlas.zim", width, height, &flags, imageData)) { PanicAlert("Failed to load ppge_atlas.zim.\n\nPlace it in the directory \"assets\" under your PPSSPP directory."); ERROR_LOG(SCEGE, "PPGe init failed - no atlas texture. PPGe stuff will not be drawn."); return; } - u32 atlasSize = height * width / 2; // it's a 4-bit paletted texture in ram - atlasWidth = width; - atlasHeight = height; + u32 atlasSize = height[0] * width[0] / 2; // it's a 4-bit paletted texture in ram + atlasWidth = width[0]; + atlasHeight = height[0]; dlPtr = __PPGeDoAlloc(dlSize, false, "PPGe Display List"); dataPtr = __PPGeDoAlloc(dataSize, false, "PPGe Vertex Data"); __PPGeSetupListArgs(); @@ -189,11 +189,11 @@ void __PPGeInit() palette[i] = (val << 12) | 0xFFF; } - const u32_le *imagePtr = (u32_le *)imageData; + const u32_le *imagePtr = (u32_le *)imageData[0]; u8 *ramPtr = (u8 *)Memory::GetPointer(atlasPtr); // Palettize to 4-bit, the easy way. - for (int i = 0; i < width * height / 2; i++) { + for (int i = 0; i < width[0] * height[0] / 2; i++) { // Each pixel is 16 bits, so this loads two pixels. u32 c = imagePtr[i]; // It's white anyway, so we only look at one channel of each pixel. @@ -203,7 +203,7 @@ void __PPGeInit() ramPtr[i] = cval; } - free(imageData); + free(imageData[0]); DEBUG_LOG(SCEGE, "PPGe drawing library initialized. DL: %08x Data: %08x Atlas: %08x (%i) Args: %08x", dlPtr, dataPtr, atlasPtr, atlasSize, listArgs.ptr); From eaa4743285ae3763cd0fa165d6be157777401f4d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 12:32:58 -0800 Subject: [PATCH 09/22] Fix a very minor leak. --- Windows/main.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/Windows/main.cpp b/Windows/main.cpp index eb5c677e24..b13be5b24f 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -287,25 +287,24 @@ void System_SendMessage(const char *command, const char *parameter) { } } -void EnableCrashingOnCrashes() { - typedef BOOL (WINAPI *tGetPolicy)(LPDWORD lpFlags); - typedef BOOL (WINAPI *tSetPolicy)(DWORD dwFlags); - const DWORD EXCEPTION_SWALLOWING = 0x1; +void EnableCrashingOnCrashes() { + typedef BOOL (WINAPI *tGetPolicy)(LPDWORD lpFlags); + typedef BOOL (WINAPI *tSetPolicy)(DWORD dwFlags); + const DWORD EXCEPTION_SWALLOWING = 0x1; - HMODULE kernel32 = LoadLibrary(L"kernel32.dll"); - tGetPolicy pGetPolicy = (tGetPolicy)GetProcAddress(kernel32, - "GetProcessUserModeExceptionPolicy"); - tSetPolicy pSetPolicy = (tSetPolicy)GetProcAddress(kernel32, - "SetProcessUserModeExceptionPolicy"); - if (pGetPolicy && pSetPolicy) - { - DWORD dwFlags; - if (pGetPolicy(&dwFlags)) - { - // Turn off the filter - pSetPolicy(dwFlags & ~EXCEPTION_SWALLOWING); - } - } + HMODULE kernel32 = LoadLibrary(L"kernel32.dll"); + tGetPolicy pGetPolicy = (tGetPolicy)GetProcAddress(kernel32, + "GetProcessUserModeExceptionPolicy"); + tSetPolicy pSetPolicy = (tSetPolicy)GetProcAddress(kernel32, + "SetProcessUserModeExceptionPolicy"); + if (pGetPolicy && pSetPolicy) { + DWORD dwFlags; + if (pGetPolicy(&dwFlags)) { + // Turn off the filter. + pSetPolicy(dwFlags & ~EXCEPTION_SWALLOWING); + } + } + FreeLibrary(kernel32); } bool System_InputBoxGetString(const char *title, const char *defaultValue, char *outValue, size_t outLength) From 340029f3338e667f76c2dbc5fc6d57fc4a4ddc2f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 13:09:25 -0800 Subject: [PATCH 10/22] Avoid a bad buffer access on GE_PRIM_KEEP_PREVIOUS. --- GPU/Common/IndexGenerator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GPU/Common/IndexGenerator.cpp b/GPU/Common/IndexGenerator.cpp index a46d9796f8..5413e7f410 100644 --- a/GPU/Common/IndexGenerator.cpp +++ b/GPU/Common/IndexGenerator.cpp @@ -40,13 +40,13 @@ void IndexGenerator::Reset() { } bool IndexGenerator::PrimCompatible(int prim1, int prim2) { - if (prim1 == -1) + if (prim1 == GE_PRIM_INVALID || prim2 == GE_PRIM_KEEP_PREVIOUS) return true; return indexedPrimitiveType[prim1] == indexedPrimitiveType[prim2]; } bool IndexGenerator::PrimCompatible(int prim) const { - if (prim_ == GE_PRIM_INVALID) + if (prim_ == GE_PRIM_INVALID || prim == GE_PRIM_KEEP_PREVIOUS) return true; return indexedPrimitiveType[prim] == prim_; } From 53fb8c32657df7757d82ad7ef60e00c8b6d08f59 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 13:11:52 -0800 Subject: [PATCH 11/22] dx9: Avoid a minor leak in loading ex9. --- Windows/D3D9Base.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Windows/D3D9Base.cpp b/Windows/D3D9Base.cpp index 6f312858fe..2e817e0ea7 100644 --- a/Windows/D3D9Base.cpp +++ b/Windows/D3D9Base.cpp @@ -82,12 +82,14 @@ bool D3D9_Init(HWND wnd, bool windowed, std::string *error_message) { HRESULT result = g_pfnCreate9ex(D3D_SDK_VERSION, &d3dEx); d3d = d3dEx; if (FAILED(result)) { + FreeLibrary(hD3D9); *error_message = "D3D9Ex available but context creation failed"; return false; } } else { d3d = Direct3DCreate9(D3D_SDK_VERSION); if (!d3d) { + FreeLibrary(hD3D9); *error_message = "Failed to create D3D9 context"; return false; } From e7aabc8f53211d112967dbbdadc042cc5888686e Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 13:26:45 -0800 Subject: [PATCH 12/22] Avoid a hang on step out with no threads. --- Windows/Debugger/Debugger_Disasm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Windows/Debugger/Debugger_Disasm.cpp b/Windows/Debugger/Debugger_Disasm.cpp index 0aa1f762e2..77e8a3f54c 100644 --- a/Windows/Debugger/Debugger_Disasm.cpp +++ b/Windows/Debugger/Debugger_Disasm.cpp @@ -316,7 +316,7 @@ void CDisasm::stepOut() auto threads = GetThreadsInfo(); - u32 entry, stackTop; + u32 entry = cpu->GetPC(), stackTop = 0; for (size_t i = 0; i < threads.size(); i++) { if (threads[i].isCurrent) From d5c7fb3f0e8179b49cb44af771d7b51028d143f4 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 13:48:26 -0800 Subject: [PATCH 13/22] Avoid an out of bounds mem access. --- Core/HLE/sceKernelThread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index 102f9a1adb..d95b0dd85b 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -1500,7 +1500,7 @@ u32 sceKernelReferThreadStatus(u32 threadID, u32 statusPtr) t->nt.nativeSize = THREADINFO_SIZE_AFTER_260; if (wantedSize != 0) - Memory::Memcpy(statusPtr, &t->nt, wantedSize); + Memory::Memcpy(statusPtr, &t->nt, std::min(wantedSize, (u32)sizeof(t->nt))); // TODO: What is this value? Basic tests show 0... if (wantedSize > sizeof(t->nt)) Memory::Memset(statusPtr + sizeof(t->nt), 0, wantedSize - sizeof(t->nt)); From e980486719d96e72c4b4379f78d149f2c0223977 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 14:00:54 -0800 Subject: [PATCH 14/22] Fix a small memory leak in video card detection. --- Windows/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Windows/main.cpp b/Windows/main.cpp index b13be5b24f..d806e1c397 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -185,6 +185,7 @@ std::string GetVideoCardDriverVersion() { hr = pIWbemLocator->ConnectServer(bstrServer, NULL, NULL, 0L, 0L, NULL, NULL, &pIWbemServices); if (FAILED(hr)) { pIWbemLocator->Release(); + SysFreeString(bstrServer); CoUninitialize(); return retvalue; } From de8ffc18b30629ec549a3e7e7442bff144df1cd9 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 18:27:44 -0800 Subject: [PATCH 15/22] Match up two arrays for error messages. --- Common/ArmEmitter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Common/ArmEmitter.cpp b/Common/ArmEmitter.cpp index 05664def00..433dfa6d5c 100644 --- a/Common/ArmEmitter.cpp +++ b/Common/ArmEmitter.cpp @@ -844,7 +844,9 @@ const char *InstNames[] = { "AND", "ORR", "MOV", "BIC", - "MVN" + "MVN", + "MOVW", + "MOVT", }; void ARMXEmitter::AND (ARMReg Rd, ARMReg Rn, Operand2 Rm) { WriteInstruction(0, Rd, Rn, Rm); } From fa84bb69488a93e38b181161840df3897c4f0bdb Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 18:36:41 -0800 Subject: [PATCH 16/22] Fix some unlikely uninitialized values. --- Windows/Debugger/CtrlRegisterList.cpp | 76 ++++++++++++--------------- Windows/Debugger/CtrlRegisterList.h | 1 + 2 files changed, 35 insertions(+), 42 deletions(-) diff --git a/Windows/Debugger/CtrlRegisterList.cpp b/Windows/Debugger/CtrlRegisterList.cpp index f21c564e60..c142b774ef 100644 --- a/Windows/Debugger/CtrlRegisterList.cpp +++ b/Windows/Debugger/CtrlRegisterList.cpp @@ -291,6 +291,9 @@ void CtrlRegisterList::onPaint(WPARAM wParam, LPARAM lParam) value = cpu->GetLo(); len = sprintf(temp,"lo"); break; + default: + temp[0] = '\0'; + break; } SetTextColor(hdc,0x600000); @@ -366,22 +369,18 @@ void CtrlRegisterList::redraw() UpdateWindow(wnd); } -void CtrlRegisterList::copyRegisterValue() +u32 CtrlRegisterList::getSelectedRegValue(char *out, size_t size) { - if (!Core_IsStepping()) - { - MessageBox(wnd,L"Can't copy register values while the core is running.",L"Error",MB_OK); - return; - } - - int cat = category; int reg = selection; u32 val; - if (selection >= cpu->GetNumRegsInCategory(cat)) + if (selection >= cpu->GetNumRegsInCategory(category)) { - if (cat != 0 || selection >= REGISTERS_END) - return; + if (category != 0 || selection >= REGISTERS_END) + { + *out = '\0'; + return -1; + } switch (selection) { @@ -394,14 +393,29 @@ void CtrlRegisterList::copyRegisterValue() case REGISTER_LO: val = cpu->GetLo(); break; + default: + *out = '\0'; + return -1; } - } else { - val = cpu->GetRegValue(cat,reg); + } + else + val = cpu->GetRegValue(category, reg); + + snprintf(out, size, "%08X", val); + return val; +} + +void CtrlRegisterList::copyRegisterValue() +{ + if (!Core_IsStepping()) + { + MessageBox(wnd,L"Can't copy register values while the core is running.",L"Error",MB_OK); + return; } char temp[24]; - sprintf(temp,"%08X",val); - W32Util::CopyTextToClipboard(wnd,temp); + getSelectedRegValue(temp, 24); + W32Util::CopyTextToClipboard(wnd, temp); } void CtrlRegisterList::editRegisterValue() @@ -412,33 +426,9 @@ void CtrlRegisterList::editRegisterValue() return; } - int cat = category; + char temp[24]; + u32 val = getSelectedRegValue(temp, 24); int reg = selection; - u32 val; - - if (selection >= cpu->GetNumRegsInCategory(cat)) - { - if (cat != 0 || selection >= REGISTERS_END) - return; - - switch (selection) - { - case REGISTER_PC: - val = cpu->GetPC(); - break; - case REGISTER_HI: - val = cpu->GetHi(); - break; - case REGISTER_LO: - val = cpu->GetLo(); - break; - } - } else { - val = cpu->GetRegValue(cat,reg); - } - - char temp[256]; - sprintf(temp,"0x%08X",val); std::string value = temp; if (InputBox_GetString(GetModuleHandle(NULL),wnd,L"Set new value",value,value)) { @@ -457,7 +447,7 @@ void CtrlRegisterList::editRegisterValue() cpu->SetLo(val); break; default: - cpu->SetRegValue(cat,reg,val); + cpu->SetRegValue(category, reg, val); break; } redraw(); @@ -531,6 +521,8 @@ void CtrlRegisterList::onMouseUp(WPARAM wParam, LPARAM lParam, int button) case REGISTER_LO: val = cpu->GetLo(); break; + default: + return; } } else diff --git a/Windows/Debugger/CtrlRegisterList.h b/Windows/Debugger/CtrlRegisterList.h index 6f1a80ee86..fcaa78967e 100644 --- a/Windows/Debugger/CtrlRegisterList.h +++ b/Windows/Debugger/CtrlRegisterList.h @@ -45,6 +45,7 @@ class CtrlRegisterList bool *changedCat0Regs; bool ctrlDown; + u32 getSelectedRegValue(char *out, size_t size); void copyRegisterValue(); void editRegisterValue(); public: From 3fcf695159187e5a4e5c7ac4b233f892cb4f5c92 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 18:45:03 -0800 Subject: [PATCH 17/22] Fix an unlikely leak on error. --- GPU/Directx9/FramebufferDX9.cpp | 1 + GPU/GLES/Framebuffer.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/GPU/Directx9/FramebufferDX9.cpp b/GPU/Directx9/FramebufferDX9.cpp index 6fea682086..9d114843f3 100644 --- a/GPU/Directx9/FramebufferDX9.cpp +++ b/GPU/Directx9/FramebufferDX9.cpp @@ -876,6 +876,7 @@ namespace DX9 { textureCache_->ForgetLastTexture(); nvfb->fbo = fbo_create(nvfb->width, nvfb->height, 1, true, (FBOColorDepth)nvfb->colorDepth); if (!(nvfb->fbo)) { + delete nvfb; ERROR_LOG(SCEGE, "Error creating FBO! %i x %i", nvfb->renderWidth, nvfb->renderHeight); return; } diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index 33028db70f..492304c76e 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -1195,6 +1195,7 @@ void FramebufferManager::ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool s textureCache_->ForgetLastTexture(); nvfb->fbo = fbo_create(nvfb->width, nvfb->height, 1, false, (FBOColorDepth)nvfb->colorDepth); if (!(nvfb->fbo)) { + delete nvfb; ERROR_LOG(SCEGE, "Error creating FBO! %i x %i", nvfb->renderWidth, nvfb->renderHeight); return; } From dcf54ec8a0b4ca4c15671705b1d4195a403b7d46 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 18:48:50 -0800 Subject: [PATCH 18/22] armjit: Burn less hard without a quad mapping. --- Core/MIPS/ARM/ArmRegCacheFPU.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Core/MIPS/ARM/ArmRegCacheFPU.cpp b/Core/MIPS/ARM/ArmRegCacheFPU.cpp index 494c06f67b..6c03a19b67 100644 --- a/Core/MIPS/ARM/ArmRegCacheFPU.cpp +++ b/Core/MIPS/ARM/ArmRegCacheFPU.cpp @@ -916,6 +916,8 @@ ARMReg ArmRegCacheFPU::QMapReg(int vreg, VectorSize sz, int flags) { // Find where we want to map it, obeying the constraints we gave. int quad = QGetFreeQuad(start, count, "mapping"); + if (quad < 0) + return INVALID_REG; // If parts of our register are elsewhere, and we are dirty, we need to flush them // before we reload in a new location. From 6382d794a761ec235cb82d820f8500d6b20aabc4 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 18:54:01 -0800 Subject: [PATCH 19/22] Fix a debugger leak in an error case. --- Core/Debugger/DisassemblyManager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/Debugger/DisassemblyManager.cpp b/Core/Debugger/DisassemblyManager.cpp index 84a51b76b0..b35f7ca8a9 100644 --- a/Core/Debugger/DisassemblyManager.cpp +++ b/Core/Debugger/DisassemblyManager.cpp @@ -639,6 +639,7 @@ void DisassemblyFunction::load() dataSize = 16; break; default: + delete macro; return; } From b6d6f26160536cc5097f65436300d612746c2187 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 18:56:55 -0800 Subject: [PATCH 20/22] Fix an uninitialized value. --- Windows/W32Util/ShellUtil.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Windows/W32Util/ShellUtil.cpp b/Windows/W32Util/ShellUtil.cpp index 6b7aa9a19c..f14739afd6 100644 --- a/Windows/W32Util/ShellUtil.cpp +++ b/Windows/W32Util/ShellUtil.cpp @@ -125,13 +125,13 @@ namespace W32Util } AsyncBrowseDialog::AsyncBrowseDialog(HWND parent, UINT completeMsg, std::wstring title) - : type_(DIR), parent_(parent), completeMsg_(completeMsg), title_(title), complete_(false) { + : type_(DIR), parent_(parent), completeMsg_(completeMsg), title_(title), complete_(false), result_(false) { thread_ = new std::thread(std::bind(&AsyncBrowseDialog::Execute, this)); thread_->detach(); } AsyncBrowseDialog::AsyncBrowseDialog(Type type, HWND parent, UINT completeMsg, std::wstring title, std::wstring initialFolder, std::wstring filter, std::wstring extension) - : type_(type), parent_(parent), completeMsg_(completeMsg), title_(title), initialFolder_(initialFolder), filter_(filter), extension_(extension), complete_(false) { + : type_(type), parent_(parent), completeMsg_(completeMsg), title_(title), initialFolder_(initialFolder), filter_(filter), extension_(extension), complete_(false), result_(false) { thread_ = new std::thread(std::bind(&AsyncBrowseDialog::Execute, this)); thread_->detach(); } From 116ddaaaf49c1ed47d8beed10ab5365501b0d369 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 19:49:47 -0800 Subject: [PATCH 21/22] Fix a bad nullcheck. --- Common/KeyMap.cpp | 1 + UI/CwCheatScreen.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 1e3a573106..f4d55282eb 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -390,6 +390,7 @@ void SetDefaultKeyMap(DefaultMaps dmap, bool replace) { case DEFAULT_MAPPING_BLACKBERRY_QWERTY: SetDefaultKeyMap(DEVICE_ID_KEYBOARD, defaultBlackberryQWERTYKeyMap, ARRAY_SIZE(defaultBlackberryQWERTYKeyMap), replace); replace = false; + // Intentional fallthrough. case DEFAULT_MAPPING_PAD: SetDefaultKeyMap(DEVICE_ID_PAD_0, defaultPadMap, ARRAY_SIZE(defaultPadMap), replace); break; diff --git a/UI/CwCheatScreen.h b/UI/CwCheatScreen.h index 3f3dbcb85a..d08e6e160f 100644 --- a/UI/CwCheatScreen.h +++ b/UI/CwCheatScreen.h @@ -64,11 +64,11 @@ public: virtual void Draw(UIContext &dc); UI::EventReturn OnClicked(UI::EventParams &e) { + bool temp = false; if (toggle_) { *toggle_ = !(*toggle_); + temp = *toggle_; } - bool temp; - temp = *toggle_; if (temp) { activatedCheat = text_; processFileOn(activatedCheat); From 5875cea30a02430216921a30b8928df91b5e380a Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Jan 2015 19:49:58 -0800 Subject: [PATCH 22/22] Fix a mistaken case fallthrough. --- Windows/WndMainWindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index 4f9170b02c..3e4ffa7a39 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -1130,6 +1130,7 @@ namespace MainWindow break; } } + break; case WM_TIMER: // Hack: Take the opportunity to also show/hide the mouse cursor in fullscreen mode.