[misc] fix some benign Coverity warnings

This commit is contained in:
Pete Batard 2023-06-18 19:09:15 +02:00
parent be5b590cfb
commit 7eb9a6f16b
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
4 changed files with 17 additions and 22 deletions

View file

@ -344,23 +344,19 @@ static __inline int DrawTextU(HDC hDC, LPCSTR lpText, int nCount, LPRECT lpRect,
static __inline int GetWindowTextU(HWND hWnd, char* lpString, int nMaxCount)
{
int ret = 0;
DWORD err = ERROR_INVALID_DATA;
if (nMaxCount < 0)
return 0;
DWORD err = ERROR_INVALID_PARAMETER;
if (lpString == NULL || nMaxCount < 1)
goto out;
// Handle the empty string as GetWindowTextW() returns 0 then
if ((lpString != NULL) && (nMaxCount > 0))
lpString[0] = 0;
// coverity[returned_null]
lpString[0] = 0;
walloc(lpString, nMaxCount);
ret = GetWindowTextW(hWnd, wlpString, nMaxCount);
err = GetLastError();
// coverity[var_deref_model]
if ( (ret != 0) && ((ret = wchar_to_utf8_no_alloc(wlpString, lpString, nMaxCount)) == 0) ) {
if ((ret != 0) && ((ret = wchar_to_utf8_no_alloc(wlpString, lpString, nMaxCount)) == 0))
err = GetLastError();
}
wfree(lpString);
if (lpString != NULL)
lpString[nMaxCount - 1] = 0;
lpString[nMaxCount - 1] = 0;
out:
SetLastError(err);
return ret;
}