From 2fea53a873920ffe4428726d405dae8a9aa695f7 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 8 Jan 2019 20:15:14 +0300 Subject: mirlua: crashfix: winapi: use dynamic buffer size for GetWindowTextW (enhancement) pass proper buffer size to GetWindowTextW (fix) --- plugins/MirLua/Modules/WinAPI/src/winapi.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) mode change 100644 => 100755 plugins/MirLua/Modules/WinAPI/src/winapi.cpp (limited to 'plugins/MirLua/Modules/WinAPI/src/winapi.cpp') diff --git a/plugins/MirLua/Modules/WinAPI/src/winapi.cpp b/plugins/MirLua/Modules/WinAPI/src/winapi.cpp old mode 100644 new mode 100755 index 2fe8f9f3b3..8ef0708d7d --- a/plugins/MirLua/Modules/WinAPI/src/winapi.cpp +++ b/plugins/MirLua/Modules/WinAPI/src/winapi.cpp @@ -360,14 +360,15 @@ static int global_FindWindowEx(lua_State *L) static int global_GetWindowText(lua_State *L) { const HWND hwnd = (HWND)luaM_checkhwnd(L, 1); - - wchar_t buf[2048] = { 0 }; - int res = GetWindowTextW(hwnd, buf, sizeof(buf)); + int buf_size = GetWindowTextLengthW(hwnd); + wchar_t *buf = (wchar_t*)mir_alloc((buf_size + 1) * sizeof(wchar_t)); + int res = GetWindowTextW(hwnd, buf, (buf_size + 1) * sizeof(wchar_t)); if (res > 0 || GetLastError() == ERROR_SUCCESS) lua_pushstring(L, T2Utf(buf)); else lua_pushnil(L); + mir_free(buf); return 1; } -- cgit v1.2.3