Avoid null termination issues on long paths.

This commit is contained in:
Unknown W. Brackets 2015-04-08 11:55:16 -07:00
parent 3cb474047b
commit 5452129dfe

View file

@ -154,19 +154,20 @@ UI::EventReturn CwCheatScreen::OnEditCheatFile(UI::EventParams &params) {
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;