[core] fix 'Bad label' errors with empty labels

* Only happens on Win7 due to MinGW not automatically initializing variables to zero on that platform.
* Root of the problem was that GetWindowTextU() did not properly handle empty text controls, due to
  GetWindowTextW() returning 0 on empty strings. As a result, the UTF-8 label was not properly set to
  the empty string, but kept whatever data it contained, which is garbage on Windows 7 and resulted in
  an invalid label (even after sanitizing, since we don't sanitize low-level ASCII characters).
* Closes #1352
This commit is contained in:
Pete Batard 2019-08-01 18:07:44 +01:00
parent c8fda3e4e8
commit 307e2f7075
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
2 changed files with 8 additions and 5 deletions

View file

@ -329,6 +329,9 @@ static __inline int GetWindowTextU(HWND hWnd, char* lpString, int nMaxCount)
{
int ret = 0;
DWORD err = ERROR_INVALID_DATA;
// Handle the empty string as GetWindowTextW() returns 0 then
if ((lpString != NULL) && (nMaxCount > 0))
lpString[0] = 0;
// coverity[returned_null]
walloc(lpString, nMaxCount);
ret = GetWindowTextW(hWnd, wlpString, nMaxCount);