Fix additional C4267 warnings in test code with simple casts

Co-authored-by: tkreuzer <313067+tkreuzer@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-08-21 20:25:40 +00:00
parent 10d0022f29
commit cfb533d282
6 changed files with 24 additions and 23 deletions

View File

@@ -131,7 +131,7 @@ static
wchar_t * wcsistr_plus(const wchar_t *s, wchar_t *b) wchar_t * wcsistr_plus(const wchar_t *s, wchar_t *b)
{ {
wchar_t * result = wcsistr(s, b); wchar_t * result = wcsistr(s, b);
UINT len = wcslen(b); UINT len = (UINT)wcslen(b);
// workarounds // workarounds
if (!result && b[len - 1] == L' ' && wcschr(s, L',') != NULL) if (!result && b[len - 1] == L' ' && wcschr(s, L',') != NULL)
{ {

View File

@@ -331,7 +331,7 @@ GetProfileSize(
ULARGE_INTEGER Size; ULARGE_INTEGER Size;
BOOL bResult = TRUE; BOOL bResult = TRUE;
dwProfilePathLength = wcslen(pszProfilePath); dwProfilePathLength = (DWORD)wcslen(pszProfilePath);
wcscat(pszProfilePath, L"\\*.*"); wcscat(pszProfilePath, L"\\*.*");
@@ -475,7 +475,7 @@ AddUserProfile(
FindClose(hFile); FindClose(hFile);
/* Get the length of the profile path */ /* Get the length of the profile path */
dwProfilePathLength = wcslen(szProfilePath); dwProfilePathLength = (DWORD)wcslen(szProfilePath);
/* Check for the ntuser.dat file */ /* Check for the ntuser.dat file */
wcscat(szProfilePath, L"\\ntuser.dat"); wcscat(szProfilePath, L"\\ntuser.dat");

View File

@@ -466,7 +466,7 @@ static void testCharPrevW(const TESTS_CHARPREV *pEntry, SIZE_T len, UINT i)
} }
else else
{ {
b = pchW >= wszCurrent && pchW <= wszCurrent + wcslen(pEntry->lpszCurrent); b = pchW >= wszCurrent && pchW <= wszCurrent + (int)wcslen(pEntry->lpszCurrent);
if (iRealOffset >= 0) if (iRealOffset >= 0)
ok(b, "[%u] CharPrevW: pchW (0x%p) is expected to be within wszCurrent (0x%p)\n", i, pchW, wszCurrent); ok(b, "[%u] CharPrevW: pchW (0x%p) is expected to be within wszCurrent (0x%p)\n", i, pchW, wszCurrent);
else else
@@ -524,7 +524,7 @@ static void testCharPrevA(const TESTS_CHARPREV *pEntry, SIZE_T len, UINT i)
} }
else else
{ {
b = pchA >= szCurrent && pchA <= szCurrent + wcslen(pEntry->lpszCurrent); b = pchA >= szCurrent && pchA <= szCurrent + (int)wcslen(pEntry->lpszCurrent);
if (iRealOffset >= 0) if (iRealOffset >= 0)
ok(b, "[%u] CharPrevA: pchA (0x%p) is expected to be within szCurrent (0x%p)\n", i, pchA, szCurrent); ok(b, "[%u] CharPrevA: pchA (0x%p) is expected to be within szCurrent (0x%p)\n", i, pchA, szCurrent);
else else

View File

@@ -76,21 +76,22 @@ CheckBuffer(
{ \ { \
BOOLEAN _Check; \ BOOLEAN _Check; \
SIZE_T SizeOfString = wcslen(String) * sizeof(WCHAR) + sizeof(UNICODE_NULL); \ SIZE_T SizeOfString = wcslen(String) * sizeof(WCHAR) + sizeof(UNICODE_NULL); \
TestUserObjectInfo(Handle, Index, NULL, 0, FALSE, ERROR_INSUFFICIENT_BUFFER, SizeOfString); \ DWORD DwordSizeOfString = (DWORD)SizeOfString; \
TestUserObjectInfo(Handle, Index, UlongToPtr(1), 0, FALSE, ERROR_INSUFFICIENT_BUFFER, SizeOfString); \ TestUserObjectInfo(Handle, Index, NULL, 0, FALSE, ERROR_INSUFFICIENT_BUFFER, DwordSizeOfString); \
TestUserObjectInfo(Handle, Index, UlongToPtr(1), 0, FALSE, ERROR_INSUFFICIENT_BUFFER, DwordSizeOfString); \
TestUserObjectInfo(Handle, Index, NULL, 1, FALSE, ERROR_NOACCESS, NOTSET); \ TestUserObjectInfo(Handle, Index, NULL, 1, FALSE, ERROR_NOACCESS, NOTSET); \
TestUserObjectInfo(Handle, Index, UlongToPtr(1), 1, FALSE, ERROR_NOACCESS, NOTSET); \ TestUserObjectInfo(Handle, Index, UlongToPtr(1), 1, FALSE, ERROR_NOACCESS, NOTSET); \
RtlFillMemory(Buffer, BufferSize, 0x55); \ RtlFillMemory(Buffer, BufferSize, 0x55); \
TestUserObjectInfo(Handle, Index, Buffer, SizeOfString - 2, FALSE, ERROR_INSUFFICIENT_BUFFER, SizeOfString); \ TestUserObjectInfo(Handle, Index, Buffer, (DWORD)(SizeOfString - 2), FALSE, ERROR_INSUFFICIENT_BUFFER, DwordSizeOfString); \
_Check = CheckBuffer(Buffer, BufferSize, 0x55); \ _Check = CheckBuffer(Buffer, BufferSize, 0x55); \
ok(_Check == TRUE, "CheckBuffer failed\n"); \ ok(_Check == TRUE, "CheckBuffer failed\n"); \
RtlFillMemory(Buffer, BufferSize, 0x55); \ RtlFillMemory(Buffer, BufferSize, 0x55); \
TestUserObjectInfo(Handle, Index, Buffer, SizeOfString - 1, FALSE, ERROR_INSUFFICIENT_BUFFER, SizeOfString); \ TestUserObjectInfo(Handle, Index, Buffer, (DWORD)(SizeOfString - 1), FALSE, ERROR_INSUFFICIENT_BUFFER, DwordSizeOfString); \
_Check = CheckBuffer(Buffer, BufferSize, 0x55); \ _Check = CheckBuffer(Buffer, BufferSize, 0x55); \
ok(_Check == TRUE, "CheckBuffer failed\n"); \ ok(_Check == TRUE, "CheckBuffer failed\n"); \
RtlFillMemory(Buffer, BufferSize, 0x55); \ RtlFillMemory(Buffer, BufferSize, 0x55); \
Buffer[BufferSize / sizeof(WCHAR) - 1] = UNICODE_NULL; \ Buffer[BufferSize / sizeof(WCHAR) - 1] = UNICODE_NULL; \
TestUserObjectInfo(Handle, Index, Buffer, SizeOfString, TRUE, 0xdeadbeef, SizeOfString); \ TestUserObjectInfo(Handle, Index, Buffer, (DWORD)SizeOfString, TRUE, 0xdeadbeef, DwordSizeOfString); \
ok(wcscmp(Buffer, String) == 0, "Buffer '%ls', expected '%ls'\n", Buffer, String); \ ok(wcscmp(Buffer, String) == 0, "Buffer '%ls', expected '%ls'\n", Buffer, String); \
_Check = CheckBuffer(Buffer + SizeOfString / sizeof(Buffer[0]), BufferSize - SizeOfString - sizeof(WCHAR), 0x55); \ _Check = CheckBuffer(Buffer + SizeOfString / sizeof(Buffer[0]), BufferSize - SizeOfString - sizeof(WCHAR), 0x55); \
ok(_Check == TRUE, "CheckBuffer failed\n"); \ ok(_Check == TRUE, "CheckBuffer failed\n"); \

View File

@@ -158,7 +158,7 @@ static void add_message_(int line, const struct recvd_message *msg)
sprintf(seq->output, "%s: %p %04x wp %08Ix lp %08Ix", sprintf(seq->output, "%s: %p %04x wp %08Ix lp %08Ix",
msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam); msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam);
if (msg->flags & (sent | posted | parent | defwinproc | beginpaint)) if (msg->flags & (sent | posted | parent | defwinproc | beginpaint))
sprintf(seq->output + strlen(seq->output), " (flags %x)", msg->flags); sprintf(seq->output + (DWORD)strlen(seq->output), " (flags %x)", msg->flags);
} }
} }
} }

View File

@@ -176,7 +176,7 @@ static void test_FileDescriptor(FILEGROUPDESCRIPTORW* Descriptor)
ok_hex(FileDescriptor->ftLastWriteTime.dwHighDateTime, FileTime.dwHighDateTime); ok_hex(FileDescriptor->ftLastWriteTime.dwHighDateTime, FileTime.dwHighDateTime);
ok_hex(FileDescriptor->ftLastWriteTime.dwLowDateTime, FileTime.dwLowDateTime); ok_hex(FileDescriptor->ftLastWriteTime.dwLowDateTime, FileTime.dwLowDateTime);
ok_hex(FileDescriptor->nFileSizeHigh, 0); ok_hex(FileDescriptor->nFileSizeHigh, 0);
ok_hex(FileDescriptor->nFileSizeLow, strlen(test_file_1_contents)); ok_hex(FileDescriptor->nFileSizeLow, (DWORD)(DWORD)strlen(test_file_1_contents));
ok_wstr(FileDescriptor->cFileName, L"test_file_for_zip.txt"); ok_wstr(FileDescriptor->cFileName, L"test_file_for_zip.txt");
} }
} }
@@ -213,7 +213,7 @@ static void test_FileDescriptor_Folder(FILEGROUPDESCRIPTORW* Descriptor)
ok_hex(FileDescriptor->ftLastWriteTime.dwHighDateTime, FileTime.dwHighDateTime); ok_hex(FileDescriptor->ftLastWriteTime.dwHighDateTime, FileTime.dwHighDateTime);
ok_hex(FileDescriptor->ftLastWriteTime.dwLowDateTime, FileTime.dwLowDateTime); ok_hex(FileDescriptor->ftLastWriteTime.dwLowDateTime, FileTime.dwLowDateTime);
ok_hex(FileDescriptor->nFileSizeHigh, 0); ok_hex(FileDescriptor->nFileSizeHigh, 0);
ok_hex(FileDescriptor->nFileSizeLow, strlen(test_file_2_contents)); ok_hex(FileDescriptor->nFileSizeLow, (DWORD)(DWORD)strlen(test_file_2_contents));
ok_wstr(FileDescriptor->cFileName, L"folder_1\\test_file_for_zip.txt"); ok_wstr(FileDescriptor->cFileName, L"folder_1\\test_file_for_zip.txt");
} }
} }
@@ -234,7 +234,7 @@ static void test_FileContents1(IStream* Stream)
ok_wstr(statstg.pwcsName, L"test_file_for_zip.txt"); ok_wstr(statstg.pwcsName, L"test_file_for_zip.txt");
ok_hex(statstg.type, STGTY_STREAM); ok_hex(statstg.type, STGTY_STREAM);
ok_int(statstg.cbSize.LowPart, strlen(test_file_1_contents)); ok_int(statstg.cbSize.LowPart, (DWORD)(DWORD)strlen(test_file_1_contents));
ok_hex(statstg.cbSize.HighPart, 0); ok_hex(statstg.cbSize.HighPart, 0);
ok_hex(statstg.mtime.dwHighDateTime, FileTime.dwHighDateTime); ok_hex(statstg.mtime.dwHighDateTime, FileTime.dwHighDateTime);
ok_hex(statstg.mtime.dwLowDateTime, FileTime.dwLowDateTime); ok_hex(statstg.mtime.dwLowDateTime, FileTime.dwLowDateTime);
@@ -260,14 +260,14 @@ static void test_FileContents1(IStream* Stream)
ULONG cbRead; ULONG cbRead;
hr = Stream->Read(buf, sizeof(buf)-1, &cbRead); hr = Stream->Read(buf, sizeof(buf)-1, &cbRead);
ok_hex(hr, S_FALSE); ok_hex(hr, S_FALSE);
ok_int(cbRead, strlen(test_file_1_contents)); ok_int(cbRead, (DWORD)(DWORD)strlen(test_file_1_contents));
ok_str(buf, test_file_1_contents); ok_str(buf, test_file_1_contents);
hr = Stream->Seek(Offset, STREAM_SEEK_CUR, &NewPosition); hr = Stream->Seek(Offset, STREAM_SEEK_CUR, &NewPosition);
ok_hex(hr, g_bOldZipfldr ? E_NOTIMPL : S_OK); ok_hex(hr, g_bOldZipfldr ? E_NOTIMPL : S_OK);
ok_int(NewPosition.HighPart, 0); ok_int(NewPosition.HighPart, 0);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
ok_int(NewPosition.LowPart, strlen(test_file_1_contents)); ok_int(NewPosition.LowPart, (DWORD)(DWORD)strlen(test_file_1_contents));
ULONG cbWritten; ULONG cbWritten;
hr = Stream->Write("DUMMY", 5, &cbWritten); hr = Stream->Write("DUMMY", 5, &cbWritten);
@@ -291,7 +291,7 @@ static void test_FileContents1(IStream* Stream)
ok_hex(hr, g_bOldZipfldr ? E_NOTIMPL : S_OK); ok_hex(hr, g_bOldZipfldr ? E_NOTIMPL : S_OK);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
ok_int(statstg.cbSize.LowPart, strlen(test_file_1_contents)); ok_int(statstg.cbSize.LowPart, (DWORD)strlen(test_file_1_contents));
CoTaskMemFree(statstg.pwcsName); CoTaskMemFree(statstg.pwcsName);
} }
@@ -305,7 +305,7 @@ static void test_FileContents1(IStream* Stream)
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
hr = Stream->Read(buf, sizeof(buf)-1, &cbRead); hr = Stream->Read(buf, sizeof(buf)-1, &cbRead);
ok_hex(hr, S_FALSE); ok_hex(hr, S_FALSE);
ok_int(cbRead, strlen(test_file_1_contents)); ok_int(cbRead, (DWORD)strlen(test_file_1_contents));
} }
} }
@@ -324,7 +324,7 @@ static void test_FileContents2(IStream* Stream)
ok_wstr(statstg.pwcsName, L"test_file_for_zip.txt"); ok_wstr(statstg.pwcsName, L"test_file_for_zip.txt");
ok_hex(statstg.type, STGTY_STREAM); ok_hex(statstg.type, STGTY_STREAM);
ok_int(statstg.cbSize.LowPart, strlen(test_file_2_contents)); ok_int(statstg.cbSize.LowPart, (DWORD)strlen(test_file_2_contents));
ok_hex(statstg.cbSize.HighPart, 0); ok_hex(statstg.cbSize.HighPart, 0);
ok_hex(statstg.mtime.dwHighDateTime, FileTime.dwHighDateTime); ok_hex(statstg.mtime.dwHighDateTime, FileTime.dwHighDateTime);
ok_hex(statstg.mtime.dwLowDateTime, FileTime.dwLowDateTime); ok_hex(statstg.mtime.dwLowDateTime, FileTime.dwLowDateTime);
@@ -350,14 +350,14 @@ static void test_FileContents2(IStream* Stream)
ULONG cbRead; ULONG cbRead;
hr = Stream->Read(buf, sizeof(buf)-1, &cbRead); hr = Stream->Read(buf, sizeof(buf)-1, &cbRead);
ok_hex(hr, S_FALSE); ok_hex(hr, S_FALSE);
ok_int(cbRead, strlen(test_file_2_contents)); ok_int(cbRead, (DWORD)strlen(test_file_2_contents));
ok_str(buf, test_file_2_contents); ok_str(buf, test_file_2_contents);
hr = Stream->Seek(Offset, STREAM_SEEK_CUR, &NewPosition); hr = Stream->Seek(Offset, STREAM_SEEK_CUR, &NewPosition);
ok_hex(hr, g_bOldZipfldr ? E_NOTIMPL : S_OK); ok_hex(hr, g_bOldZipfldr ? E_NOTIMPL : S_OK);
ok_int(NewPosition.HighPart, 0); ok_int(NewPosition.HighPart, 0);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
ok_int(NewPosition.LowPart, strlen(test_file_2_contents)); ok_int(NewPosition.LowPart, (DWORD)strlen(test_file_2_contents));
ULONG cbWritten; ULONG cbWritten;
hr = Stream->Write("DUMMY", 5, &cbWritten); hr = Stream->Write("DUMMY", 5, &cbWritten);
@@ -381,7 +381,7 @@ static void test_FileContents2(IStream* Stream)
ok_hex(hr, g_bOldZipfldr ? E_NOTIMPL : S_OK); ok_hex(hr, g_bOldZipfldr ? E_NOTIMPL : S_OK);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
ok_int(statstg.cbSize.LowPart, strlen(test_file_2_contents)); ok_int(statstg.cbSize.LowPart, (DWORD)strlen(test_file_2_contents));
CoTaskMemFree(statstg.pwcsName); CoTaskMemFree(statstg.pwcsName);
} }
@@ -395,7 +395,7 @@ static void test_FileContents2(IStream* Stream)
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
hr = Stream->Read(buf, sizeof(buf)-1, &cbRead); hr = Stream->Read(buf, sizeof(buf)-1, &cbRead);
ok_hex(hr, S_FALSE); ok_hex(hr, S_FALSE);
ok_int(cbRead, strlen(test_file_2_contents)); ok_int(cbRead, (DWORD)strlen(test_file_2_contents));
ok_str(buf, test_file_2_contents); ok_str(buf, test_file_2_contents);
} }
} }