Fix crash in InputBox.cpp by offering an overloaded func which takes a size, and use it in MenuScreens.cpp / PSPOskDialog.cpp.

This commit is contained in:
The Dax 2013-08-05 22:45:51 -04:00
parent d20ac3c4c2
commit 4570d83c05
4 changed files with 28 additions and 6 deletions

View file

@ -772,7 +772,8 @@ int PSPOskDialog::NativeKeyboard()
ERROR_LOG(HLE, "NativeKeyboard: initial text length is too long");
sprintf(buf, "VALUE");
}
if(!InputBox_GetString(0, MainWindow::hwndMain, NULL, buf, input)) {
if(!InputBox_GetString(0, MainWindow::hwndMain, NULL, buf, input, FieldMaxLength() - 1)) {
sprintf(input, "");
}
#endif

View file

@ -1540,14 +1540,19 @@ void SystemScreen::render() {
// so until then, this is Windows/Desktop only.
#ifdef _WIN32
char nickname[512];
sprintf(nickname, "%s %s", s->T("System Nickname: "), g_Config.sNickName);
memset(nickname, 0, sizeof(nickname));
sprintf(nickname, "%s %s", s->T("System Nickname: "), g_Config.sNickName.c_str());
ui_draw2d.DrawTextShadow(UBUNTU24, nickname, x, y += stride, 0xFFFFFFFF, ALIGN_LEFT);
HLinear hlinearNick(x + 400, y, 10);
if(UIButton(GEN_ID, hlinearNick, 110, 0, s->T("Change"), ALIGN_LEFT)) {
char name[256];
memset(&name, 0, sizeof(name));
if(InputBox_GetString(MainWindow::GetHInstance(), MainWindow::hwndMain, NULL, "PPSSPP", name))
const size_t name_len = 256;
char name[name_len];
memset(name, 0, sizeof(name));
if(InputBox_GetString(MainWindow::GetHInstance(), MainWindow::hwndMain, NULL, "PPSSPP", name, name_len))
g_Config.sNickName.assign(name);
else
g_Config.sNickName.assign("PPSSPP");

View file

@ -49,6 +49,22 @@ bool InputBox_GetString(HINSTANCE hInst, HWND hParent, TCHAR *title, TCHAR *defa
return false;
}
bool InputBox_GetString(HINSTANCE hInst, HWND hParent, TCHAR *title, TCHAR *defaultvalue, TCHAR *outvalue, u32 outlength)
{
if (defaultvalue && strlen(defaultvalue)<255)
strcpy(textBoxContents,defaultvalue);
else
strcpy(textBoxContents,"");
if (IDOK==DialogBox(hInst,(LPCSTR)IDD_INPUTBOX,hParent,InputBoxFunc))
{
strncpy(outvalue, out, outlength);
return true;
}
else
return false;
}
bool InputBox_GetHex(HINSTANCE hInst, HWND hParent, TCHAR *title, u32 defaultvalue, u32 &outvalue)
{
sprintf(textBoxContents,"%08x",defaultvalue);

View file

@ -3,6 +3,6 @@
#include "Globals.h"
#include "Common/CommonWindows.h"
bool InputBox_GetString(HINSTANCE hInst, HWND hParent, TCHAR *title, TCHAR *defaultvalue, TCHAR *outvalue);
bool InputBox_GetString(HINSTANCE hInst, HWND hParent, TCHAR *title, TCHAR *defaultvalue, TCHAR *outvalue, u32 outlength);
bool InputBox_GetHex(HINSTANCE hInst, HWND hParent, TCHAR *title, u32 defaultvalue, u32 &outvalue);