[REACTOS] Fix SIZE_T related warnings

This commit is contained in:
Timo Kreuzer 2019-05-26 15:00:21 +02:00
parent 826704ba6b
commit 7611cc2b12
21 changed files with 103 additions and 46 deletions

View file

@ -1688,7 +1688,7 @@ main (
)
{
//ULONG Flags = 0;
int i;
intptr_t i;
uintptr_t j;
char a;
int bus_id = -1;

View file

@ -894,7 +894,7 @@ static void delete_stat_item(int n)
static char *ReadConversion(const char *formula)
{
int len = strlen(formula);
intptr_t len = strlen(formula);
char *str = (char *)malloc(len+3);
if (str == NULL)

View file

@ -187,7 +187,7 @@ GetAutostartEntriesFromRegistry ( HKEY hRootKey, TCHAR* KeyName )
SendMessage(hStartupListCtrl, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
}
switch (PtrToLong(hRootKey))
switch ((ULONG_PTR)hRootKey)
{
case (ULONG_PTR)HKEY_LOCAL_MACHINE:
_tcscpy(Path, _T("HKLM\\\0"));

View file

@ -52,7 +52,7 @@ FileQueryFiles(IN LPCWSTR Path,
WIN32_FIND_DATAW find_data;
LPWSTR lpszQuery;
DWORD dwNumOfChars;
SIZE_T dwNumOfChars;
LPWSTR lpszExpandedQuery;
HANDLE search;
@ -93,7 +93,7 @@ FileQueryFiles(IN LPCWSTR Path,
BOOL BackupIniFile(IN LPCWSTR lpszIniFile)
{
BOOL Success = FALSE;
DWORD dwNumOfChars = 0;
SIZE_T dwNumOfChars = 0;
LPWSTR SourceFile, DestFile;
LPWSTR lpName, lpPath;

View file

@ -31,7 +31,7 @@ MemFree(IN PVOID lpMem)
PVOID
MemAlloc(IN DWORD dwFlags,
IN DWORD dwBytes)
IN SIZE_T dwBytes)
{
/* Allocate memory from the heap */
return HeapAlloc(g_hHeap, dwFlags, dwBytes);

View file

@ -25,7 +25,7 @@ MemFree(IN PVOID lpMem);
PVOID
MemAlloc(IN DWORD dwFlags,
IN DWORD dwBytes);
IN SIZE_T dwBytes);
LPWSTR
FormatDateTime(IN LPSYSTEMTIME pDateTime);

View file

@ -560,7 +560,7 @@ SaveSettings(VOID)
Settings.wpPos.rcNormalPosition.bottom,
Settings.wpPos.showCmd);
dwSize = wcslen(buffer) * sizeof(WCHAR);
dwSize = (DWORD)(wcslen(buffer) * sizeof(WCHAR));
RegSetValueExW(hKeyEventVwr, L"Window", 0, REG_SZ, (LPBYTE)buffer, dwSize);
Quit:
@ -1173,9 +1173,9 @@ FormatInteger(LONGLONG Num, LPWSTR pwszResult, UINT cchResultMax)
UINT
FormatByteSize(LONGLONG cbSize, LPWSTR pwszResult, UINT cchResultMax)
{
INT cchWritten;
UINT cchWritten, cchRemaining;
LPWSTR pwszEnd;
size_t cchRemaining;
size_t cchStringRemaining;
/* Write formated bytes count */
cchWritten = FormatInteger(cbSize, pwszResult, cchResultMax);
@ -1185,7 +1185,8 @@ FormatByteSize(LONGLONG cbSize, LPWSTR pwszResult, UINT cchResultMax)
/* Copy " bytes" to buffer */
pwszEnd = pwszResult + cchWritten;
cchRemaining = cchResultMax - cchWritten;
StringCchCopyExW(pwszEnd, cchRemaining, L" ", &pwszEnd, &cchRemaining, 0);
StringCchCopyExW(pwszEnd, cchRemaining, L" ", &pwszEnd, &cchStringRemaining, 0);
cchRemaining = (UINT)cchStringRemaining;
cchWritten = LoadStringW(hInst, IDS_BYTES_FORMAT, pwszEnd, cchRemaining);
cchRemaining -= cchWritten;
@ -1195,9 +1196,9 @@ FormatByteSize(LONGLONG cbSize, LPWSTR pwszResult, UINT cchResultMax)
LPWSTR
FormatFileSizeWithBytes(const PULARGE_INTEGER lpQwSize, LPWSTR pwszResult, UINT cchResultMax)
{
UINT cchWritten;
UINT cchWritten, cchRemaining;
LPWSTR pwszEnd;
size_t cchRemaining;
size_t cchCopyRemaining;
/* Format bytes in KBs, MBs etc */
if (StrFormatByteSizeW(lpQwSize->QuadPart, pwszResult, cchResultMax) == NULL)
@ -1208,10 +1209,11 @@ FormatFileSizeWithBytes(const PULARGE_INTEGER lpQwSize, LPWSTR pwszResult, UINT
return pwszResult;
/* Concatenate " (" */
cchWritten = wcslen(pwszResult);
cchWritten = (UINT)wcslen(pwszResult);
pwszEnd = pwszResult + cchWritten;
cchRemaining = cchResultMax - cchWritten;
StringCchCopyExW(pwszEnd, cchRemaining, L" (", &pwszEnd, &cchRemaining, 0);
StringCchCopyExW(pwszEnd, cchRemaining, L" (", &pwszEnd, &cchCopyRemaining, 0);
cchRemaining = (UINT)cchCopyRemaining;
/* Write formated bytes count */
cchWritten = FormatByteSize(lpQwSize->QuadPart, pwszEnd, cchRemaining);
@ -1231,7 +1233,8 @@ GetFileTimeString(LPFILETIME lpFileTime, LPWSTR pwszResult, UINT cchResult)
FILETIME ft;
SYSTEMTIME st;
int cchWritten;
size_t cchRemaining = cchResult;
UINT cchRemaining = cchResult;
size_t cchCopyRemaining;
LPWSTR pwszEnd = pwszResult;
if (!FileTimeToLocalFileTime(lpFileTime, &ft) || !FileTimeToSystemTime(&ft, &st))
@ -1246,7 +1249,8 @@ GetFileTimeString(LPFILETIME lpFileTime, LPWSTR pwszResult, UINT cchResult)
cchRemaining -= cchWritten;
pwszEnd += cchWritten;
StringCchCopyExW(pwszEnd, cchRemaining, L", ", &pwszEnd, &cchRemaining, 0);
StringCchCopyExW(pwszEnd, cchRemaining, L", ", &pwszEnd, &cchCopyRemaining, 0);
cchRemaining = (UINT)cchCopyRemaining;
cchWritten = GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, pwszEnd, cchRemaining);
if (cchWritten)
@ -1294,7 +1298,7 @@ AllocEventLog(IN PCWSTR ComputerName OPTIONAL,
IN BOOL Permanent)
{
PEVENTLOG EventLog;
UINT cchName;
SIZE_T cchName;
/* Allocate a new event log entry */
EventLog = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*EventLog));
@ -1467,7 +1471,7 @@ GetExpandedFilePathName(
OUT LPWSTR lpFullFileName OPTIONAL,
IN DWORD nSize)
{
DWORD dwLength;
SIZE_T dwLength;
/* Determine the needed size after expansion of any environment strings */
dwLength = ExpandEnvironmentStringsW(lpFileName, NULL, 0);

View file

@ -505,7 +505,7 @@ AddDisplayDevice(PINFO pInfo, PDISPLAY_DEVICEW DisplayDevice)
LPWSTR name = NULL;
LPWSTR key = NULL;
LPWSTR devid = NULL;
DWORD descriptionSize, nameSize, keySize, devidSize;
SIZE_T descriptionSize, nameSize, keySize, devidSize;
PSETTINGS_ENTRY Current;
DWORD ResolutionsCount = 1;
DWORD i;

View file

@ -199,7 +199,8 @@ WriteRdpFile(HANDLE hFile,
PRDPSETTINGS pRdpSettings)
{
WCHAR line[MAXKEY + MAXVALUE + 4];
DWORD BytesToWrite, BytesWritten;
SIZE_T BytesToWrite;
ULONG BytesWritten;
BOOL bRet;
INT i, k;

View file

@ -9,7 +9,7 @@ PCHAR *GetSubkeyNames( PCHAR MainKeyName, PCHAR Append ) {
DWORD Error;
HKEY MainKey;
PCHAR *Out, OutKeyName;
DWORD CharTotal = 0, AppendLen = 1 + strlen(Append);
SIZE_T CharTotal = 0, AppendLen = 1 + strlen(Append);
DWORD MaxSubKeyLen = 0, MaxSubKeys = 0;
Error = RegOpenKey( HKEY_LOCAL_MACHINE, MainKeyName, &MainKey );

View file

@ -12,8 +12,13 @@ ssize_t send_packet( struct interface_info *ip,
struct in_addr addr,
struct sockaddr_in *broadcast,
struct hardware *hardware ) {
int result =
sendto( ip->wfdesc, (char *)p, size, 0,
int result;
if (size > INT_MAX)
return WSAEMSGSIZE;
result =
sendto( ip->wfdesc, (char *)p, (int)size, 0,
(struct sockaddr *)broadcast, sizeof(*broadcast) );
if (result < 0) {
@ -32,8 +37,13 @@ ssize_t receive_packet(struct interface_info *ip,
struct sockaddr_in *dest,
struct hardware *hardware ) {
int recv_addr_size = sizeof(*dest);
int result =
recvfrom (ip -> rfdesc, (char *)packet_data, packet_len, 0,
int result;
if (packet_len > INT_MAX)
return WSAEMSGSIZE;
result =
recvfrom (ip -> rfdesc, (char *)packet_data, (int)packet_len, 0,
(struct sockaddr *)dest, &recv_addr_size );
return result;
}

View file

@ -119,7 +119,7 @@ ArcGetNextTokenA(
{
NTSTATUS Status;
PCSTR p = ArcPath;
ULONG SpecifierLength;
SIZE_T SpecifierLength;
ULONG KeyValue;
/*
@ -133,6 +133,10 @@ ArcGetNextTokenA(
return NULL; /* Path starts with '(' and is thus invalid */
SpecifierLength = (p - ArcPath) * sizeof(CHAR);
if (SpecifierLength > MAXUSHORT)
{
return NULL;
}
/*
* The strtoul function skips any leading whitespace.
@ -163,7 +167,7 @@ ArcGetNextTokenA(
if (!NT_SUCCESS(Status))
return NULL;
TokenSpecifier->Length = strlen(TokenSpecifier->Buffer) * sizeof(CHAR);
TokenSpecifier->Length = (USHORT)SpecifierLength;
/* We succeeded, return the token key value */
*Key = KeyValue;
@ -180,7 +184,7 @@ ArcGetNextTokenU(
{
NTSTATUS Status;
PCWSTR p = ArcPath;
ULONG SpecifierLength;
SIZE_T SpecifierLength;
ULONG KeyValue;
/*
@ -194,6 +198,10 @@ ArcGetNextTokenU(
return NULL; /* Path starts with '(' and is thus invalid */
SpecifierLength = (p - ArcPath) * sizeof(WCHAR);
if (SpecifierLength > UNICODE_STRING_MAX_BYTES)
{
return NULL;
}
++p;
@ -226,7 +234,7 @@ ArcGetNextTokenU(
if (!NT_SUCCESS(Status))
return NULL;
TokenSpecifier->Length = wcslen(TokenSpecifier->Buffer) * sizeof(WCHAR);
TokenSpecifier->Length = (USHORT)SpecifierLength;
/* We succeeded, return the token key value */
*Key = KeyValue;
@ -308,6 +316,7 @@ ArcPathNormalize(
NTSTATUS Status;
PCWSTR EndOfArcName;
PCWSTR p;
SIZE_T PathLength;
if (NormalizedArcPath->MaximumLength < sizeof(UNICODE_NULL))
return FALSE;
@ -350,7 +359,13 @@ ArcPathNormalize(
if (!NT_SUCCESS(Status))
return FALSE;
NormalizedArcPath->Length = wcslen(NormalizedArcPath->Buffer) * sizeof(WCHAR);
PathLength = wcslen(NormalizedArcPath->Buffer);
if (PathLength > UNICODE_STRING_MAX_CHARS)
{
return FALSE;
}
NormalizedArcPath->Length = (USHORT)PathLength * sizeof(WCHAR);
return TRUE;
}
@ -685,6 +700,7 @@ ResolveArcNameManually(
CONTROLLER_TYPE ControllerType;
PERIPHERAL_TYPE PeripheralType;
BOOLEAN UseSignature;
SIZE_T NameLength;
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry = NULL;
@ -787,7 +803,13 @@ ResolveArcNameManually(
}
/* Update NtName length */
NtName->Length = wcslen(NtName->Buffer) * sizeof(WCHAR);
NameLength = wcslen(NtName->Buffer);
if (NameLength > UNICODE_STRING_MAX_CHARS)
{
return STATUS_NAME_TOO_LONG;
}
NtName->Length = (USHORT)NameLength * sizeof(WCHAR);
return STATUS_SUCCESS;
}
@ -802,6 +824,7 @@ ArcPathToNtPath(
NTSTATUS Status;
PCWSTR BeginOfPath;
UNICODE_STRING ArcName;
SIZE_T PathLength;
/* TODO: We should "normalize" the path, i.e. expand all the xxx() into xxx(0) */
@ -877,7 +900,14 @@ ArcPathToNtPath(
return FALSE;
}
}
NtPath->Length = wcslen(NtPath->Buffer) * sizeof(WCHAR);
PathLength = wcslen(NtPath->Buffer);
if (PathLength > UNICODE_STRING_MAX_CHARS)
{
return FALSE;
}
NtPath->Length = (USHORT)PathLength * sizeof(WCHAR);
return TRUE;
}

View file

@ -39,7 +39,7 @@ NTAPI
CsrpConnectToServer(IN PWSTR ObjectDirectory)
{
NTSTATUS Status;
ULONG PortNameLength;
SIZE_T PortNameLength;
UNICODE_STRING PortName;
LARGE_INTEGER CsrSectionViewSize;
HANDLE CsrSectionHandle;
@ -62,10 +62,15 @@ CsrpConnectToServer(IN PWSTR ObjectDirectory)
/* Calculate the total port name size */
PortNameLength = ((wcslen(ObjectDirectory) + 1) * sizeof(WCHAR)) +
sizeof(CSR_PORT_NAME);
if (PortNameLength > UNICODE_STRING_MAX_BYTES)
{
DPRINT1("PortNameLength too big: %Iu", PortNameLength);
return STATUS_NAME_TOO_LONG;
}
/* Set the port name */
PortName.Length = 0;
PortName.MaximumLength = PortNameLength;
PortName.MaximumLength = (USHORT)PortNameLength;
/* Allocate a buffer for it */
PortName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, PortNameLength);
@ -366,11 +371,18 @@ CsrClientCallServer(IN OUT PCSR_API_MESSAGE ApiMessage,
ULONG PointerCount;
PULONG_PTR OffsetPointer;
/* Make sure the length is valid */
if (DataLength > (MAXSHORT - sizeof(CSR_API_MESSAGE)))
{
DPRINT1("DataLength too big: %lu", DataLength);
return STATUS_INVALID_PARAMETER;
}
/* Fill out the Port Message Header */
ApiMessage->Header.u2.ZeroInit = 0;
ApiMessage->Header.u1.s1.TotalLength = DataLength +
ApiMessage->Header.u1.s1.TotalLength = (CSHORT)DataLength +
sizeof(CSR_API_MESSAGE) - sizeof(ApiMessage->Data); // FIELD_OFFSET(CSR_API_MESSAGE, Data) + DataLength;
ApiMessage->Header.u1.s1.DataLength = DataLength +
ApiMessage->Header.u1.s1.DataLength = (CSHORT)DataLength +
FIELD_OFFSET(CSR_API_MESSAGE, Data) - sizeof(ApiMessage->Header); // ApiMessage->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE);
/* Fill out the CSR Header */

View file

@ -2365,7 +2365,7 @@ LdrpInitializeProcess(IN PCONTEXT Context,
{
WCHAR szCSDVersion[128];
LONG i;
ULONG Length = ARRAYSIZE(szCSDVersion) - 1;
USHORT Length = (USHORT)ARRAYSIZE(szCSDVersion) - 1;
i = _snwprintf(szCSDVersion, Length,
L"Service Pack %d",
((Peb->OSCSDVersion >> 8) & 0xFF));

View file

@ -67,7 +67,7 @@ LdrpAllocateUnicodeString(IN OUT PUNICODE_STRING StringOut,
if (Length != UNICODE_STRING_MAX_BYTES)
{
/* It's not, so set the maximum length to be one char more */
StringOut->MaximumLength = Length + sizeof(UNICODE_NULL);
StringOut->MaximumLength = (USHORT)Length + sizeof(UNICODE_NULL);
}
else
{

View file

@ -157,7 +157,7 @@ RtlGetNtVersionNumbers(OUT PULONG pMajorVersion,
NTSTATUS NTAPI
RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
{
ULONG Length;
SIZE_T Length;
PPEB Peb = NtCurrentPeb();
if (lpVersionInformation->dwOSVersionInfoSize != sizeof(RTL_OSVERSIONINFOW) &&

View file

@ -357,7 +357,7 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
IO_STATUS_BLOCK IoStatus;
PFILE_OBJECT FileObject;
PMMPAGING_FILE PagingFile;
ULONG AllocMapSize;
SIZE_T AllocMapSize;
ULONG Count;
KPROCESSOR_MODE PreviousMode;
UNICODE_STRING PageFileName;

View file

@ -351,7 +351,7 @@ HRESULT inline SHSetStrRet(LPSTRRET pStrRet, LPCSTR pstrValue)
HRESULT inline SHSetStrRet(LPSTRRET pStrRet, LPCWSTR pwstrValue)
{
ULONG cchr = wcslen(pwstrValue);
SIZE_T cchr = wcslen(pwstrValue);
LPWSTR buffer = static_cast<LPWSTR>(CoTaskMemAlloc((cchr + 1) * sizeof(WCHAR)));
if (buffer == NULL)
return E_OUTOFMEMORY;

View file

@ -515,7 +515,7 @@ RtlIpv6AddressToStringA(
ASSERT(Result >= Buffer);
ASSERT(Result < Buffer + RTL_NUMBER_OF(Buffer));
Status = RtlUnicodeToMultiByteN(S, RTLIPV6A2S_MAX_LEN, NULL, Buffer, (wcslen(Buffer) + 1) * sizeof(WCHAR));
Status = RtlUnicodeToMultiByteN(S, RTLIPV6A2S_MAX_LEN, NULL, Buffer, (ULONG)(wcslen(Buffer) + 1) * sizeof(WCHAR));
if (!NT_SUCCESS(Status))
return (PSTR)~0;
@ -544,7 +544,7 @@ RtlIpv6AddressToStringExA(
if (!NT_SUCCESS(Status))
return Status;
Status = RtlUnicodeToMultiByteN(AddressString, RTLIPV6A2SEX_MAX_LEN, NULL, Buffer, (wcslen(Buffer) + 1) * sizeof(WCHAR));
Status = RtlUnicodeToMultiByteN(AddressString, RTLIPV6A2SEX_MAX_LEN, NULL, Buffer, (*AddressStringLength + 1) * sizeof(WCHAR));
if (!NT_SUCCESS(Status))
return STATUS_INVALID_PARAMETER;

View file

@ -309,7 +309,7 @@ RtlpCollapsePath(PWSTR Path, /* ULONG PathBufferSize, ULONG PathLength, */ ULONG
// FIXME: Do not suppose NULL-terminated strings!!
ULONG PathLength = wcslen(Path);
SIZE_T PathLength = wcslen(Path);
PWSTR EndBuffer = Path + PathLength; // Path + PathBufferSize / sizeof(WCHAR);
PWSTR EndPath;

View file

@ -905,7 +905,7 @@ VideoPortScanRom(
IN ULONG RomLength,
IN PUCHAR String)
{
ULONG StringLength;
SIZE_T StringLength;
BOOLEAN Found;
PUCHAR SearchLocation;