Author: tkreuzer Date: Mon Sep 19 11:09:09 2011 New Revision: 53746
URL: http://svn.reactos.org/svn/reactos?rev=53746&view=rev Log: [RTL] - Fix a number of MSVC/amd64 warnings/problems - Remove code duplication in RtlCharToInteger and RtlUnicodeStringToInteger - Fixup too large string length in RtlInitAnsiString, RtlInitUnicodeString - Use symbolic constants instead of hardcoded values - Fix overflow check in RtlInitUnicodeStringEx
Modified: trunk/reactos/include/ndk/rtlfuncs.h trunk/reactos/lib/rtl/acl.c trunk/reactos/lib/rtl/actctx.c trunk/reactos/lib/rtl/amd64/unwind.c trunk/reactos/lib/rtl/image.c trunk/reactos/lib/rtl/ppb.c trunk/reactos/lib/rtl/unicode.c
Modified: trunk/reactos/include/ndk/rtlfuncs.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/rtlfuncs.h?rev=... ============================================================================== --- trunk/reactos/include/ndk/rtlfuncs.h [iso-8859-1] (original) +++ trunk/reactos/include/ndk/rtlfuncs.h [iso-8859-1] Mon Sep 19 11:09:09 2011 @@ -1118,7 +1118,7 @@ IN ULONG Revision, IN ULONG Flags, IN ULONG MandatoryFlags, - IN ULONG AceType, + IN UCHAR AceType, IN PSID LabelSid);
NTSYSAPI @@ -1993,7 +1993,7 @@ NTAPI RtlFillMemoryUlong( IN PVOID Destination, - IN ULONG Length, + IN SIZE_T Length, IN ULONG Fill );
Modified: trunk/reactos/lib/rtl/acl.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/acl.c?rev=53746&... ============================================================================== --- trunk/reactos/lib/rtl/acl.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/acl.c [iso-8859-1] Mon Sep 19 11:09:09 2011 @@ -110,7 +110,7 @@ GUID *ObjectTypeGuid OPTIONAL, GUID *InheritedObjectTypeGuid OPTIONAL, PSID Sid, - ULONG Type) + UCHAR Type) { PACE Ace; PSID SidStart; @@ -223,7 +223,7 @@ }
/* initialize the header and common fields */ - Ace->Header.AceFlags = Flags; + Ace->Header.AceFlags = (BYTE)Flags; Ace->Header.AceType = Type; Ace->Header.AceSize = (WORD)AceSize; Ace->AccessMask = AccessMask; @@ -253,7 +253,7 @@ /* copy the SID */ RtlCopySid(RtlLengthSid(Sid), SidStart, Sid); Acl->AceCount++; - Acl->AclRevision = Revision; + Acl->AclRevision = (BYTE)Revision;
return STATUS_SUCCESS; } @@ -322,7 +322,7 @@ IN GUID *InheritedObjectTypeGuid OPTIONAL, IN PSID Sid) { - ULONG Type; + UCHAR Type; PAGED_CODE_RTL();
/* make sure we call RtlpAddKnownAce correctly */ @@ -405,7 +405,7 @@ IN GUID *InheritedObjectTypeGuid OPTIONAL, IN PSID Sid) { - ULONG Type; + UCHAR Type; PAGED_CODE_RTL();
/* make sure we call RtlpAddKnownAce correctly */ @@ -465,6 +465,7 @@ ULONG Index; PAGED_CODE_RTL();
+ /* Make sure, the ACL is valid */ if (Acl->AclRevision < MIN_ACL_REVISION || Acl->AclRevision > MAX_ACL_REVISION || !RtlFirstFreeAce(Acl, &Ace)) @@ -472,8 +473,10 @@ return STATUS_INVALID_PARAMETER; }
+ /* Check if the ACL revision is smaller than the given one */ if (Acl->AclRevision <= AclRevision) { + /* Update the revision to the given one */ AclRevision = Acl->AclRevision; }
@@ -510,6 +513,7 @@ AceListLength, Current, (ULONG)((ULONG_PTR)Ace - (ULONG_PTR)Current)); + Acl->AceCount = Acl->AceCount + NewAceCount; Acl->AclRevision = AclRevision;
@@ -591,7 +595,7 @@ BOOLEAN Success, BOOLEAN Failure) { - ULONG Type; + UCHAR Type;
if (Success) { @@ -630,7 +634,7 @@ IN ULONG Revision, IN ULONG Flags, IN ULONG MandatoryFlags, - IN ULONG AceType, + IN UCHAR AceType, IN PSID LabelSid) { if (MandatoryFlags & ~SYSTEM_MANDATORY_LABEL_VALID_MASK)
Modified: trunk/reactos/lib/rtl/actctx.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/actctx.c?rev=53746&... ============================================================================== --- trunk/reactos/lib/rtl/actctx.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/actctx.c [iso-8859-1] Mon Sep 19 11:09:09 2011 @@ -3,7 +3,7 @@ * PROJECT: ReactOS Runtime Library * PURPOSE: Activation Context Support * FILE: lib/rtl/actctx.c - * PROGRAMERS: + * PROGRAMERS: * Jon Griffiths * Eric Pouech * Jacek Caban for CodeWeavers @@ -241,7 +241,7 @@ UNICODE_STRING res;
res.Buffer = (PWSTR)xmlstr->ptr; - res.Length = res.MaximumLength = xmlstr->len * sizeof(WCHAR); + res.Length = res.MaximumLength = (USHORT)xmlstr->len * sizeof(WCHAR);
return res; } @@ -647,7 +647,7 @@ if (ptr == xmlbuf->end || *ptr != '=') return FALSE;
name->ptr = xmlbuf->ptr; - name->len = ptr-xmlbuf->ptr; + name->len = (ULONG)(ptr - xmlbuf->ptr); xmlbuf->ptr = ptr;
ptr++; @@ -663,7 +663,7 @@ return FALSE; }
- value->len = ptr - value->ptr; + value->len = (ULONG)(ptr - value->ptr); xmlbuf->ptr = ptr + 1;
if (xmlbuf->ptr == xmlbuf->end) return FALSE; @@ -705,7 +705,7 @@ ptr++;
elem->ptr = xmlbuf->ptr; - elem->len = ptr - xmlbuf->ptr; + elem->len = (ULONG)(ptr - xmlbuf->ptr); xmlbuf->ptr = ptr; return xmlbuf->ptr != xmlbuf->end; } @@ -733,7 +733,7 @@ if (!ptr) return FALSE;
content->ptr = xmlbuf->ptr; - content->len = ptr - xmlbuf->ptr; + content->len = (ULONG)(ptr - xmlbuf->ptr); xmlbuf->ptr = ptr;
return TRUE; @@ -1555,7 +1555,7 @@ : ACTIVATION_CONTEXT_PATH_TYPE_NONE;
unicode_tests = IS_TEXT_UNICODE_SIGNATURE | IS_TEXT_UNICODE_REVERSE_SIGNATURE; - if (RtlIsTextUnicode( (PVOID) buffer, size, &unicode_tests )) + if (RtlIsTextUnicode((PVOID)buffer, (ULONG)size, &unicode_tests )) { xmlbuf.ptr = buffer; xmlbuf.end = xmlbuf.ptr + size / sizeof(WCHAR); @@ -1579,12 +1579,12 @@ else { /* let's assume utf-8 for now */ - int len; + size_t len; WCHAR *new_buff;
_SEH2_TRY { - len = mbstowcs( NULL, buffer, size); + len = mbstowcs(NULL, buffer, size); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { @@ -1628,7 +1628,7 @@ return NtOpenFile( handle, GENERIC_READ, &attr, &io, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_ALERT ); }
-static NTSTATUS get_module_filename( HMODULE module, UNICODE_STRING *str, unsigned int extra_len ) +static NTSTATUS get_module_filename( HMODULE module, UNICODE_STRING *str, USHORT extra_len ) { NTSTATUS status; ULONG magic; @@ -1881,7 +1881,7 @@ WCHAR *tmp; ULONG build, revision;
- data_len = io.Information; + data_len = (ULONG)io.Information;
for (;;) { @@ -1890,7 +1890,7 @@ NtQueryDirectoryFile( dir, 0, NULL, NULL, &io, buffer, sizeof(buffer), FileBothDirectoryInformation, FALSE, &lookup_us, FALSE ); if (io.Status != STATUS_SUCCESS) break; - data_len = io.Information; + data_len = (ULONG)io.Information; data_pos = 0; } dir_info = (FILE_BOTH_DIR_INFORMATION*)(buffer + data_pos); @@ -1905,8 +1905,8 @@ revision = atoiW(tmp); if (build == ai->version.build && revision < ai->version.revision) continue; - ai->version.build = build; - ai->version.revision = revision; + ai->version.build = (USHORT)build; + ai->version.revision = (USHORT)revision;
if ((ret = RtlAllocateHeap( RtlGetProcessHeap(), 0, dir_info->FileNameLength * sizeof(WCHAR) ))) { @@ -1935,7 +1935,7 @@
if (!ai->arch || !ai->name || !ai->public_key) return STATUS_NO_SUCH_FILE;
- if (!(path = RtlAllocateHeap( RtlGetProcessHeap(), 0, + if (!(path = RtlAllocateHeap( RtlGetProcessHeap(), 0, ((strlenW(SharedUserData->NtSystemRoot) + 1) *sizeof(WCHAR)) + sizeof(manifest_dirW) ))) return STATUS_NO_MEMORY;
@@ -2373,17 +2373,17 @@ NTAPI RtlActivateActivationContextEx( ULONG flags, PTEB tebAddress, HANDLE handle, PULONG_PTR cookie ) { RTL_ACTIVATION_CONTEXT_STACK_FRAME *frame; - + if (!(frame = RtlAllocateHeap( RtlGetProcessHeap(), 0, sizeof(*frame) ))) return STATUS_NO_MEMORY; - + frame->Previous = tebAddress->ActivationContextStackPointer->ActiveFrame; frame->ActivationContext = handle; frame->Flags = 0; - + tebAddress->ActivationContextStackPointer->ActiveFrame = frame; RtlAddRefActivationContext( handle ); - + *cookie = (ULONG_PTR)frame; DPRINT( "%p cookie=%lx\n", handle, *cookie ); return STATUS_SUCCESS; @@ -2525,11 +2525,11 @@ acdi->ulFormatVersion = assembly ? 1 : 0; /* FIXME */ acdi->ulAssemblyCount = actctx->num_assemblies; acdi->ulRootManifestPathType = assembly ? assembly->manifest.type : 0 /* FIXME */; - acdi->ulRootManifestPathChars = assembly && assembly->manifest.info ? manifest_len - 1 : 0; + acdi->ulRootManifestPathChars = assembly && assembly->manifest.info ? (DWORD)manifest_len - 1 : 0; acdi->ulRootConfigurationPathType = actctx->config.type; - acdi->ulRootConfigurationPathChars = actctx->config.info ? config_len - 1 : 0; + acdi->ulRootConfigurationPathChars = actctx->config.info ? (DWORD)config_len - 1 : 0; acdi->ulAppDirPathType = actctx->appdir.type; - acdi->ulAppDirPathChars = actctx->appdir.info ? appdir_len - 1 : 0; + acdi->ulAppDirPathChars = actctx->appdir.info ? (DWORD)appdir_len - 1 : 0; ptr = (LPWSTR)(acdi + 1); if (manifest_len) { @@ -2589,9 +2589,9 @@ }
afdi->ulFlags = 0; /* FIXME */ - afdi->ulEncodedAssemblyIdentityLength = (id_len - 1) * sizeof(WCHAR); + afdi->ulEncodedAssemblyIdentityLength = (DWORD)(id_len - 1) * sizeof(WCHAR); afdi->ulManifestPathType = assembly->manifest.type; - afdi->ulManifestPathLength = assembly->manifest.info ? (path_len - 1) * sizeof(WCHAR) : 0; + afdi->ulManifestPathLength = assembly->manifest.info ? (DWORD)(path_len - 1) * sizeof(WCHAR) : 0; /* FIXME afdi->liManifestLastWriteTime = 0; */ afdi->ulPolicyPathType = ACTIVATION_CONTEXT_PATH_TYPE_NONE; /* FIXME */ afdi->ulPolicyPathLength = 0; @@ -2601,7 +2601,7 @@ afdi->ulManifestVersionMinor = 0; afdi->ulPolicyVersionMajor = 0; /* FIXME */ afdi->ulPolicyVersionMinor = 0; /* FIXME */ - afdi->ulAssemblyDirectoryNameLength = ad_len ? (ad_len - 1) * sizeof(WCHAR) : 0; + afdi->ulAssemblyDirectoryNameLength = ad_len ? (DWORD)(ad_len - 1) * sizeof(WCHAR) : 0; ptr = (LPWSTR)(afdi + 1); afdi->lpAssemblyEncodedAssemblyIdentity = ptr; memcpy( ptr, assembly_id, id_len * sizeof(WCHAR) ); @@ -2654,7 +2654,7 @@ } if (retlen) *retlen = 0; /* yes that's what native does !! */ afdi->ulFlags = ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION; - afdi->ulFilenameLength = dll_len ? (dll_len - 1) * sizeof(WCHAR) : 0; + afdi->ulFilenameLength = dll_len ? (DWORD)(dll_len - 1) * sizeof(WCHAR) : 0; afdi->ulPathLength = 0; /* FIXME */ ptr = (LPWSTR)(afdi + 1); if (dll_len)
Modified: trunk/reactos/lib/rtl/amd64/unwind.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/amd64/unwind.c?rev=... ============================================================================== --- trunk/reactos/lib/rtl/amd64/unwind.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/amd64/unwind.c [iso-8859-1] Mon Sep 19 11:09:09 2011 @@ -59,7 +59,7 @@ OPTIONAL ULONG ExceptionHandler; OPTIONAL ULONG FunctionEntry; }; - OPTIONAL ULONG ExceptionData[]; + OPTIONAL ULONG ExceptionData[]; */ } UNWIND_INFO, *PUNWIND_INFO;
@@ -69,7 +69,7 @@ * \brief Locates the table of RUNTIME_FUNCTION entries for a code address. * \param ControlPc * Address of the code, for which the table should be searched. - * \param ImageBase + * \param ImageBase * Pointer to a DWORD64 that receives the base address of the * corresponding executable image. * \param Length @@ -354,7 +354,7 @@ IN OUT PKNONVOLATILE_CONTEXT_POINTERS ContextPointers) { PUNWIND_INFO UnwindInfo; - ULONG CodeOffset; + ULONG_PTR CodeOffset; ULONG i; UNWIND_CODE UnwindCode; BYTE Reg; @@ -524,7 +524,7 @@ ULONG64 ControlPc, ImageBase, EstablisherFrame; ULONG64 StackLow, StackHigh; PVOID HandlerData; - INT i; + ULONG i; PRUNTIME_FUNCTION FunctionEntry;
DPRINT("Enter RtlWalkFrameChain\n");
Modified: trunk/reactos/lib/rtl/image.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/image.c?rev=53746&a... ============================================================================== --- trunk/reactos/lib/rtl/image.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/image.c [iso-8859-1] Mon Sep 19 11:09:09 2011 @@ -43,7 +43,7 @@ NTAPI LdrVerifyMappedImageMatchesChecksum( IN PVOID BaseAddress, - IN ULONG ImageSize, + IN SIZE_T ImageSize, IN ULONG FileLength) { #if 0 @@ -192,7 +192,7 @@ DPRINT1("e_lfanew is larger than PE file\n"); return STATUS_INVALID_IMAGE_FORMAT; } - + /* It shouldn't be past 4GB either */ if (DosHeader->e_lfanew >= (MAXULONG - sizeof(IMAGE_DOS_SIGNATURE) - sizeof(IMAGE_FILE_HEADER))) @@ -201,7 +201,7 @@ DPRINT1("e_lfanew is larger than 4GB\n"); return STATUS_INVALID_IMAGE_FORMAT; } - + /* And the whole file shouldn't overflow past 4GB */ if ((DosHeader->e_lfanew + sizeof(IMAGE_DOS_SIGNATURE) - sizeof(IMAGE_FILE_HEADER)) >= Size) @@ -211,7 +211,7 @@ return STATUS_INVALID_IMAGE_FORMAT; } } - + /* The offset also can't be larger than 256MB, as a hard-coded check */ if (DosHeader->e_lfanew >= (256 * 1024 * 1024)) { @@ -235,7 +235,7 @@ *OutHeaders = NtHeaders; return STATUS_SUCCESS; } - + /* * @implemented */
Modified: trunk/reactos/lib/rtl/ppb.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/ppb.c?rev=53746&... ============================================================================== --- trunk/reactos/lib/rtl/ppb.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/ppb.c [iso-8859-1] Mon Sep 19 11:09:09 2011 @@ -26,7 +26,7 @@ RtlpCopyParameterString(PWCHAR *Ptr, PUNICODE_STRING Destination, PUNICODE_STRING Source, - ULONG Size) + USHORT Size) { Destination->Length = Source->Length; Destination->MaximumLength = Size ? Size : Source->MaximumLength;
Modified: trunk/reactos/lib/rtl/unicode.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/unicode.c?rev=53746... ============================================================================== --- trunk/reactos/lib/rtl/unicode.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/unicode.c [iso-8859-1] Mon Sep 19 11:09:09 2011 @@ -99,7 +99,7 @@ if (AllocateDestinationString) { UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR); - UniDest->MaximumLength = Length; + UniDest->MaximumLength = (USHORT)Length; if (!UniDest->Buffer) return STATUS_NO_MEMORY; } else if (UniDest->Length >= UniDest->MaximumLength) @@ -320,17 +320,13 @@ digit = -1; }
- if (digit < 0 || digit >= (int)base) - { - *value = bMinus ? -RunningTotal : RunningTotal; - return STATUS_SUCCESS; - } + if (digit < 0 || digit >= (int)base) break;
RunningTotal = RunningTotal * base + digit; str++; }
- *value = bMinus ? -RunningTotal : RunningTotal; + *value = bMinus ? (0 - RunningTotal) : RunningTotal; return STATUS_SUCCESS; }
@@ -518,13 +514,14 @@ RtlInitAnsiString(IN OUT PANSI_STRING DestinationString, IN PCSZ SourceString) { - ULONG DestSize; - - if(SourceString) - { - DestSize = strlen(SourceString); - DestinationString->Length = (USHORT)DestSize; - DestinationString->MaximumLength = (USHORT)DestSize + sizeof(CHAR); + SIZE_T Size; + + if (SourceString) + { + Size = strlen(SourceString); + if (Size > (MAXUSHORT - sizeof(CHAR))) Size = MAXUSHORT - sizeof(CHAR); + DestinationString->Length = (USHORT)Size; + DestinationString->MaximumLength = (USHORT)Size + sizeof(CHAR); } else { @@ -540,14 +537,14 @@ RtlInitAnsiStringEx(IN OUT PANSI_STRING DestinationString, IN PCSZ SourceString) { - ULONG DestSize; - - if(SourceString) - { - DestSize = strlen(SourceString); - if (DestSize >= 0xFFFF) return STATUS_NAME_TOO_LONG; - DestinationString->Length = (USHORT)DestSize; - DestinationString->MaximumLength = (USHORT)DestSize + sizeof(CHAR); + SIZE_T Size; + + if (SourceString) + { + Size = strlen(SourceString); + if (Size > (MAXUSHORT - sizeof(CHAR))) return STATUS_NAME_TOO_LONG; + DestinationString->Length = (USHORT)Size; + DestinationString->MaximumLength = (USHORT)Size + sizeof(CHAR); } else { @@ -582,16 +579,18 @@ */ VOID NTAPI -RtlInitUnicodeString(IN OUT PUNICODE_STRING DestinationString, - IN PCWSTR SourceString) -{ - ULONG DestSize; - - if(SourceString) - { - DestSize = wcslen(SourceString) * sizeof(WCHAR); - DestinationString->Length = (USHORT)DestSize; - DestinationString->MaximumLength = (USHORT)DestSize + sizeof(WCHAR); +RtlInitUnicodeString( + IN OUT PUNICODE_STRING DestinationString, + IN PCWSTR SourceString) +{ + SIZE_T Size; + + if (SourceString) + { + Size = wcslen(SourceString) * sizeof(WCHAR); + if (Size > (MAXUSHORT - sizeof(WCHAR))) Size = MAXUSHORT - sizeof(WCHAR); + DestinationString->Length = (USHORT)Size; + DestinationString->MaximumLength = (USHORT)Size + sizeof(WCHAR); } else { @@ -607,17 +606,18 @@ */ NTSTATUS NTAPI -RtlInitUnicodeStringEx(OUT PUNICODE_STRING DestinationString, - IN PCWSTR SourceString) -{ - ULONG DestSize; - - if(SourceString) - { - DestSize = wcslen(SourceString) * sizeof(WCHAR); - if (DestSize >= 0xFFFC) return STATUS_NAME_TOO_LONG; - DestinationString->Length = (USHORT)DestSize; - DestinationString->MaximumLength = (USHORT)DestSize + sizeof(WCHAR); +RtlInitUnicodeStringEx( + OUT PUNICODE_STRING DestinationString, + IN PCWSTR SourceString) +{ + SIZE_T Size; + + if (SourceString) + { + Size = wcslen(SourceString) * sizeof(WCHAR); + if (Size > (MAXUSHORT - sizeof(WCHAR))) return STATUS_NAME_TOO_LONG; + DestinationString->Length = (USHORT)Size; + DestinationString->MaximumLength = (USHORT)Size + sizeof(WCHAR); } else { @@ -646,7 +646,7 @@ CHAR buffer[33]; PCHAR pos; CHAR digit; - ULONG len; + SIZE_T len;
if (base == 0) { @@ -663,7 +663,7 @@ do { pos--; - digit = value % base; + digit = (CHAR)(value % base); value = value / base;
if (digit < 10) @@ -734,8 +734,8 @@ i = v % Radix; v = v / Radix;
- if (i < 10) *tp = i + L'0'; - else *tp = i + L'a' - 10; + if (i < 10) *tp = (WCHAR)(i + L'0'); + else *tp = (WCHAR)(i + L'a' - 10);
tp++; } @@ -1003,18 +1003,14 @@ digit = -1; }
- if (digit < 0 || digit >= base) - { - *value = bMinus ? -RunningTotal : RunningTotal; - return STATUS_SUCCESS; - } + if (digit < 0 || (ULONG)digit >= base) break;
RunningTotal = RunningTotal * base + digit; lpwstr++; CharsRemaining--; }
- *value = bMinus ? -RunningTotal : RunningTotal; + *value = bMinus ? (0 - RunningTotal) : RunningTotal; return STATUS_SUCCESS; }
@@ -1078,7 +1074,7 @@ if (AllocateDestinationString) { AnsiDest->Buffer = RtlpAllocateStringMemory(Length, TAG_ASTR); - AnsiDest->MaximumLength = Length; + AnsiDest->MaximumLength = (USHORT)Length;
if (!AnsiDest->Buffer) return STATUS_NO_MEMORY; } @@ -1135,7 +1131,7 @@ if (AllocateDestinationString) { UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR); - UniDest->MaximumLength = Length; + UniDest->MaximumLength = (USHORT)Length;
if (!UniDest->Buffer) return STATUS_NO_MEMORY; } @@ -1189,7 +1185,7 @@ if (AllocateDestinationString) { OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR); - OemDest->MaximumLength = Length; + OemDest->MaximumLength = (USHORT)Length;
if (!OemDest->Buffer) return STATUS_NO_MEMORY; } @@ -1378,7 +1374,7 @@ if (AllocateDestinationString) { UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR); - UniDest->MaximumLength = Length; + UniDest->MaximumLength = (USHORT)Length;
if (!UniDest->Buffer) return STATUS_NO_MEMORY; } @@ -1455,8 +1451,7 @@ NTAPI RtlEqualDomainName ( IN PUNICODE_STRING DomainName1, - IN PUNICODE_STRING DomainName2 -) + IN PUNICODE_STRING DomainName2) { return RtlEqualComputerName(DomainName1, DomainName2); } @@ -1483,8 +1478,7 @@ NTAPI RtlGUIDFromString( IN UNICODE_STRING *str, - OUT GUID* guid -) + OUT GUID* guid) { int i = 0; const WCHAR *lpszCLSID = str->Buffer; @@ -1697,7 +1691,7 @@ if (AllocateDestinationString) { OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR); - OemDest->MaximumLength = Length; + OemDest->MaximumLength = (USHORT)Length; if (!OemDest->Buffer) return STATUS_NO_MEMORY; } else if (OemDest->Length > OemDest->MaximumLength) @@ -1742,13 +1736,12 @@ NTSTATUS Status = STATUS_SUCCESS; CHAR Buffer[65]; CHAR Digit; - ULONG Len; + SIZE_T Len; PCHAR Pos;
if (Base == 0) Base = 10;
- if ((Base != 2) && (Base != 8) && - (Base != 10) && (Base != 16)) + if ((Base != 2) && (Base != 8) && (Base != 10) && (Base != 16)) { return STATUS_INVALID_PARAMETER; } @@ -1759,7 +1752,7 @@ do { Pos--; - Digit = Val % Base; + Digit = (CHAR)(Val % Base); Val = Val / Base;
if (Digit < 10) @@ -1873,7 +1866,7 @@ if (AllocateDestinationString) { AnsiDest->Buffer = RtlpAllocateStringMemory(Length, TAG_ASTR); - AnsiDest->MaximumLength = Length; + AnsiDest->MaximumLength = (USHORT)Length; if (!AnsiDest->Buffer) return STATUS_NO_MEMORY; } else if (AnsiDest->Length >= AnsiDest->MaximumLength) @@ -1931,7 +1924,7 @@ if (AllocateDestinationString) { OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR); - OemDest->MaximumLength = Length; + OemDest->MaximumLength = (USHORT)Length; if (!OemDest->Buffer) return STATUS_NO_MEMORY; } else if (OemDest->Length > OemDest->MaximumLength) @@ -1985,7 +1978,7 @@ if (AllocateDestinationString) { OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR); - OemDest->MaximumLength = Length; + OemDest->MaximumLength = (USHORT)Length; if (!OemDest->Buffer) return STATUS_NO_MEMORY; } else if (OemDest->Length >= OemDest->MaximumLength) @@ -2208,19 +2201,19 @@ IN OUT PUNICODE_STRING UniDest, IN PCWSTR Source) { - ULONG Length; + SIZE_T Size; PAGED_CODE_RTL();
- Length = (wcslen(Source) + 1) * sizeof(WCHAR); - if (Length > 0xFFFE) return FALSE; - - UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR); + Size = (wcslen(Source) + 1) * sizeof(WCHAR); + if (Size > MAXUSHORT) return FALSE; + + UniDest->Buffer = RtlpAllocateStringMemory((ULONG)Size, TAG_USTR);
if (UniDest->Buffer == NULL) return FALSE;
- RtlCopyMemory(UniDest->Buffer, Source, Length); - UniDest->MaximumLength = (USHORT)Length; - UniDest->Length = Length - sizeof (WCHAR); + RtlCopyMemory(UniDest->Buffer, Source, Size); + UniDest->MaximumLength = (USHORT)Size; + UniDest->Length = (USHORT)Size - sizeof (WCHAR);
return TRUE; } @@ -2353,19 +2346,19 @@ IN OUT PSTRING Destination, IN PCSZ Source) { - ULONG Length; + SIZE_T Size;
if (Source) { - Length = (USHORT)strlen(Source); - - if (Destination->Length + Length > Destination->MaximumLength) + Size = strlen(Source); + + if (Destination->Length + Size > Destination->MaximumLength) { return STATUS_BUFFER_TOO_SMALL; }
- RtlMoveMemory(&Destination->Buffer[Destination->Length], Source, Length); - Destination->Length += Length; + RtlMoveMemory(&Destination->Buffer[Destination->Length], Source, Size); + Destination->Length += (USHORT)Size; }
return STATUS_SUCCESS; @@ -2379,7 +2372,7 @@ RtlUpperString(PSTRING DestinationString, PSTRING SourceString) { - ULONG Length; + USHORT Length; PCHAR Src, Dest;
Length = min(SourceString->Length, @@ -2502,20 +2495,20 @@ IN PCUNICODE_STRING MatchString, OUT PUSHORT Position) { - int main_idx; - unsigned int search_idx; + SHORT i; + USHORT j;
switch (Flags) { case 0: { - for (main_idx = 0; main_idx < SearchString->Length / sizeof(WCHAR); main_idx++) + for (i = 0; i < SearchString->Length / sizeof(WCHAR); i++) { - for (search_idx = 0; search_idx < MatchString->Length / sizeof(WCHAR); search_idx++) + for (j = 0; j < MatchString->Length / sizeof(WCHAR); j++) { - if (SearchString->Buffer[main_idx] == MatchString->Buffer[search_idx]) + if (SearchString->Buffer[i] == MatchString->Buffer[j]) { - *Position = (main_idx + 1) * sizeof(WCHAR); + *Position = (i + 1) * sizeof(WCHAR); return STATUS_SUCCESS; } } @@ -2527,13 +2520,13 @@
case 1: { - for (main_idx = SearchString->Length / sizeof(WCHAR) - 1; main_idx >= 0; main_idx--) + for (i = SearchString->Length / sizeof(WCHAR) - 1; i >= 0; i--) { - for (search_idx = 0; search_idx < MatchString->Length / sizeof(WCHAR); search_idx++) + for (j = 0; j < MatchString->Length / sizeof(WCHAR); j++) { - if (SearchString->Buffer[main_idx] == MatchString->Buffer[search_idx]) + if (SearchString->Buffer[i] == MatchString->Buffer[j]) { - *Position = main_idx * sizeof(WCHAR); + *Position = i * sizeof(WCHAR); return STATUS_SUCCESS; } } @@ -2545,19 +2538,19 @@
case 2: { - for (main_idx = 0; main_idx < SearchString->Length / sizeof(WCHAR); main_idx++) + for (i = 0; i < SearchString->Length / sizeof(WCHAR); i++) { - search_idx = 0; - - while (search_idx < MatchString->Length / sizeof(WCHAR) && - SearchString->Buffer[main_idx] != MatchString->Buffer[search_idx]) + j = 0; + + while (j < MatchString->Length / sizeof(WCHAR) && + SearchString->Buffer[i] != MatchString->Buffer[j]) { - search_idx++; + j++; }
- if (search_idx >= MatchString->Length / sizeof(WCHAR)) + if (j >= MatchString->Length / sizeof(WCHAR)) { - *Position = (main_idx + 1) * sizeof(WCHAR); + *Position = (i + 1) * sizeof(WCHAR); return STATUS_SUCCESS; } } @@ -2568,19 +2561,19 @@
case 3: { - for (main_idx = SearchString->Length / sizeof(WCHAR) - 1; main_idx >= 0; main_idx--) + for (i = SearchString->Length / sizeof(WCHAR) - 1; i >= 0; i--) { - search_idx = 0; - - while (search_idx < MatchString->Length / sizeof(WCHAR) && - SearchString->Buffer[main_idx] != MatchString->Buffer[search_idx]) + j = 0; + + while (j < MatchString->Length / sizeof(WCHAR) && + SearchString->Buffer[i] != MatchString->Buffer[j]) { - search_idx++; + j++; }
- if (search_idx >= MatchString->Length / sizeof(WCHAR)) + if (j >= MatchString->Length / sizeof(WCHAR)) { - *Position = main_idx * sizeof(WCHAR); + *Position = i * sizeof(WCHAR); return STATUS_SUCCESS; } }