Merge pull request #5743 from akallabeth/32bit_warn_fix

Fix #5741: Limit strnlen checks to INT_MAX to silence compile on 32bi…
This commit is contained in:
Bernhard Miklautz 2019-11-21 15:23:19 +01:00 committed by GitHub
commit a378511617
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 6 deletions

View File

@ -37,6 +37,7 @@ typedef CHAR TCHAR;
#ifdef UNICODE
#define _tprintf wprintf
#define _sntprintf snwprintf
#define _tcslen _wcslen
#define _tcsdup _wcsdup
#define _tcscmp wcscmp
@ -50,6 +51,7 @@ typedef CHAR TCHAR;
#define _tcsnccmp wcsncmp
#else
#define _tprintf printf
#define _sntprintf snprintf
#define _tcslen strlen
#define _tcsdup _strdup
#define _tcscmp strcmp

View File

@ -16,16 +16,22 @@ int TestEnvironmentGetEnvironmentStrings(int argc, char* argv[])
lpszEnvironmentBlock = GetEnvironmentStrings();
p = (TCHAR*)lpszEnvironmentBlock;
p = lpszEnvironmentBlock;
while (p[0] && p[1])
{
const int rc = _tprintf(_T("%s\n"), p);
const int rc = _sntprintf(NULL, 0, _T("%s\n"), p);
if (rc < 1)
{
_tprintf(_T("test failed: return %d\n"), rc);
goto fail;
}
length = _tcslen(p);
if (length != (size_t)(rc - 1))
{
_tprintf(_T("test failed: length %") _T(PRIuz) _T(" != %d [%s]\n"), length, rc - 1, p);
goto fail;
}
p += (length + 1);
}

View File

@ -297,7 +297,7 @@ LONG RegQueryValueExA(HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved, LPDWORD
size_t length;
char* pData = (char*)lpData;
length = strnlen(pValue->data.string, UINT32_MAX);
length = strnlen(pValue->data.string, INT_MAX);
if (pData != NULL)
{

View File

@ -125,9 +125,9 @@ static BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogAppender* appender,
if (!fp)
return FALSE;
FileNameLength = strnlen(message->FileName, UINT32_MAX);
FunctionNameLength = strnlen(message->FunctionName, UINT32_MAX);
TextStringLength = strnlen(message->TextString, UINT32_MAX);
FileNameLength = strnlen(message->FileName, INT_MAX);
FunctionNameLength = strnlen(message->FunctionName, INT_MAX);
TextStringLength = strnlen(message->TextString, INT_MAX);
MessageLength =
16 + (4 + FileNameLength + 1) + (4 + FunctionNameLength + 1) + (4 + TextStringLength + 1);