mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
Fixed GetEnvironmentStrings test
Some os return an invalid/wrong character count if a string with unknown symbols is printed to stdout. Instead use the sprintf family and print to a buffer / determine the required buffer size.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user