diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2019-01-08 20:15:14 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2019-01-08 20:15:14 +0300 |
commit | 2fea53a873920ffe4428726d405dae8a9aa695f7 (patch) | |
tree | c470f67d5970999b9ee689fc509d80fcc0b3421b /plugins/MirLua/Modules/WinAPI | |
parent | d7a89e57b6d9c8270eb8ff68970629a0f2a16683 (diff) |
mirlua: crashfix:
winapi:
use dynamic buffer size for GetWindowTextW (enhancement)
pass proper buffer size to GetWindowTextW (fix)
Diffstat (limited to 'plugins/MirLua/Modules/WinAPI')
-rwxr-xr-x[-rw-r--r--] | plugins/MirLua/Modules/WinAPI/src/winapi.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/plugins/MirLua/Modules/WinAPI/src/winapi.cpp b/plugins/MirLua/Modules/WinAPI/src/winapi.cpp index 2fe8f9f3b3..8ef0708d7d 100644..100755 --- 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;
}
|