diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index 7f51ef3017..9e5863e536 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -154,19 +154,20 @@ UI::EventReturn CwCheatScreen::OnEditCheatFile(UI::EventParams ¶ms) { cheatFile = activeCheatFile; // Can't rely on a .txt file extension to auto-open in the right editor, // so let's find notepad - wchar_t notepad_path[MAX_PATH]; - GetSystemDirectory(notepad_path, sizeof(notepad_path) / sizeof(wchar_t)); + wchar_t notepad_path[MAX_PATH + 1]; + GetSystemDirectory(notepad_path, MAX_PATH); wcscat(notepad_path, L"\\notepad.exe"); - wchar_t cheat_path[MAX_PATH]; - wcscpy(cheat_path, ConvertUTF8ToWString(cheatFile).c_str()); + wchar_t cheat_path[MAX_PATH + 1] = {0}; + wcsncpy(cheat_path, ConvertUTF8ToWString(cheatFile).c_str(), MAX_PATH); // Flip any slashes... for (size_t i = 0; i < wcslen(cheat_path); i++) { if (cheat_path[i] == '/') cheat_path[i] = '\\'; } - wchar_t command_line[MAX_PATH * 2 + 1]; + // One for the space, one for the null. + wchar_t command_line[MAX_PATH * 2 + 1 + 1]; wsprintf(command_line, L"%s %s", notepad_path, cheat_path); STARTUPINFO si;