From a7eb2e79e536bdbfcd7345385d31876834bca425 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 16 Apr 2015 15:44:06 -0400 Subject: [PATCH 1/2] Memory Labels Class: Correct bounds clamping in ProcessCODFile --- Source/Project64/N64 System/Mips/Memory Labels Class.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Project64/N64 System/Mips/Memory Labels Class.cpp b/Source/Project64/N64 System/Mips/Memory Labels Class.cpp index 243e19b31..2830e3141 100644 --- a/Source/Project64/N64 System/Mips/Memory Labels Class.cpp +++ b/Source/Project64/N64 System/Mips/Memory Labels Class.cpp @@ -208,10 +208,10 @@ void CMemoryLabel::ProcessCODFile(BYTE * File, DWORD FileLen) } } - if (Length > 40) - { - Length = 40; - } + // Stay within label array bounds + if (Length > 39) + Length = 39; + memcpy(Label,CurrentPos,Length); Label[Length] = '\0'; From e9c056e5a4f2bcec37beb55782acd607d2425e3c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 16 Apr 2015 15:49:48 -0400 Subject: [PATCH 2/2] Notification Class: Correct array sizing in SetWindowCaption sizeof(wchar_t) is a size of 2 (or 4 if in a Linux environment). With the previous code, it would be trying to insert the null terminator at index 511 on Windows, which is incorrect. --- Source/Project64/User Interface/Notification Class.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/Project64/User Interface/Notification Class.cpp b/Source/Project64/User Interface/Notification Class.cpp index ba41100ce..1bc9df7f8 100644 --- a/Source/Project64/User Interface/Notification Class.cpp +++ b/Source/Project64/User Interface/Notification Class.cpp @@ -147,9 +147,11 @@ void CNotification::SetGfxPlugin( CGfxPlugin * Plugin ) void CNotification::SetWindowCaption (const wchar_t * Caption) { - wchar_t WinTitle[256]; - _snwprintf( WinTitle, sizeof(WinTitle), L"%s - %s", Caption, g_Settings->LoadString(Setting_ApplicationName).ToUTF16().c_str()); - WinTitle[sizeof(WinTitle) - 1] = 0; + static const size_t TITLE_SIZE = 256; + + wchar_t WinTitle[TITLE_SIZE]; + _snwprintf(WinTitle, TITLE_SIZE, L"%s - %s", Caption, g_Settings->LoadString(Setting_ApplicationName).ToUTF16().c_str()); + WinTitle[TITLE_SIZE - 1] = 0; m_hWnd->Caption(WinTitle); }