- 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

svn path=/trunk/; revision=53746
This commit is contained in:
Timo Kreuzer 2011-09-19 11:09:09 +00:00
parent 06631cf0ea
commit 080da6ec72
7 changed files with 138 additions and 141 deletions

View file

@ -1118,7 +1118,7 @@ RtlAddMandatoryAce(
IN ULONG Revision,
IN ULONG Flags,
IN ULONG MandatoryFlags,
IN ULONG AceType,
IN UCHAR AceType,
IN PSID LabelSid);
NTSYSAPI
@ -1993,7 +1993,7 @@ VOID
NTAPI
RtlFillMemoryUlong(
IN PVOID Destination,
IN ULONG Length,
IN SIZE_T Length,
IN ULONG Fill
);

View file

@ -110,7 +110,7 @@ RtlpAddKnownAce(
GUID *ObjectTypeGuid OPTIONAL,
GUID *InheritedObjectTypeGuid OPTIONAL,
PSID Sid,
ULONG Type)
UCHAR Type)
{
PACE Ace;
PSID SidStart;
@ -223,7 +223,7 @@ RtlpAddKnownAce(
}
/* 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 @@ RtlpAddKnownAce(
/* copy the SID */
RtlCopySid(RtlLengthSid(Sid), SidStart, Sid);
Acl->AceCount++;
Acl->AclRevision = Revision;
Acl->AclRevision = (BYTE)Revision;
return STATUS_SUCCESS;
}
@ -322,7 +322,7 @@ RtlAddAccessAllowedObjectAce(
IN GUID *InheritedObjectTypeGuid OPTIONAL,
IN PSID Sid)
{
ULONG Type;
UCHAR Type;
PAGED_CODE_RTL();
/* make sure we call RtlpAddKnownAce correctly */
@ -405,7 +405,7 @@ RtlAddAccessDeniedObjectAce(
IN GUID *InheritedObjectTypeGuid OPTIONAL,
IN PSID Sid)
{
ULONG Type;
UCHAR Type;
PAGED_CODE_RTL();
/* make sure we call RtlpAddKnownAce correctly */
@ -465,6 +465,7 @@ RtlAddAce(
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 @@ RtlAddAce(
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 @@ RtlAddAce(
AceListLength,
Current,
(ULONG)((ULONG_PTR)Ace - (ULONG_PTR)Current));
Acl->AceCount = Acl->AceCount + NewAceCount;
Acl->AclRevision = AclRevision;
@ -591,7 +595,7 @@ RtlAddAuditAccessObjectAce(
BOOLEAN Success,
BOOLEAN Failure)
{
ULONG Type;
UCHAR Type;
if (Success)
{
@ -630,7 +634,7 @@ RtlAddMandatoryAce(
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)

View file

@ -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 @@ static UNICODE_STRING xmlstr2unicode(const xmlstr_t *xmlstr)
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 @@ static BOOL next_xml_attr(xmlbuf_t* xmlbuf, xmlstr_t* name, xmlstr_t* value,
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 @@ static BOOL next_xml_attr(xmlbuf_t* xmlbuf, xmlstr_t* name, xmlstr_t* value,
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 @@ static BOOL next_xml_elem(xmlbuf_t* xmlbuf, xmlstr_t* elem)
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 @@ static BOOL parse_text_content(xmlbuf_t* xmlbuf, xmlstr_t* content)
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 @@ static NTSTATUS parse_manifest( struct actctx_loader* acl, struct assembly_ident
: 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 @@ static NTSTATUS parse_manifest( struct actctx_loader* acl, struct assembly_ident
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 @@ static NTSTATUS open_nt_file( HANDLE *handle, UNICODE_STRING *name )
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 @@ static WCHAR *lookup_manifest_file( HANDLE dir, struct assembly_identity *ai )
WCHAR *tmp;
ULONG build, revision;
data_len = io.Information;
data_len = (ULONG)io.Information;
for (;;)
{
@ -1890,7 +1890,7 @@ static WCHAR *lookup_manifest_file( HANDLE dir, struct assembly_identity *ai )
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 @@ static WCHAR *lookup_manifest_file( HANDLE dir, struct assembly_identity *ai )
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 @@ static NTSTATUS lookup_winsxs(struct actctx_loader* acl, struct assembly_identit
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 @@ NTSTATUS
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 @@ RtlQueryInformationActivationContext( ULONG flags, HANDLE handle, PVOID subinst,
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 @@ RtlQueryInformationActivationContext( ULONG flags, HANDLE handle, PVOID subinst,
}
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 @@ RtlQueryInformationActivationContext( ULONG flags, HANDLE handle, PVOID subinst,
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 @@ RtlQueryInformationActivationContext( ULONG flags, HANDLE handle, PVOID subinst,
}
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)

View file

@ -59,7 +59,7 @@ typedef struct _UNWIND_INFO
OPTIONAL ULONG ExceptionHandler;
OPTIONAL ULONG FunctionEntry;
};
OPTIONAL ULONG ExceptionData[];
OPTIONAL ULONG ExceptionData[];
*/
} UNWIND_INFO, *PUNWIND_INFO;
@ -69,7 +69,7 @@ typedef struct _UNWIND_INFO
* \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 @@ RtlVirtualUnwind(
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 @@ RtlWalkFrameChain(OUT PVOID *Callers,
ULONG64 ControlPc, ImageBase, EstablisherFrame;
ULONG64 StackLow, StackHigh;
PVOID HandlerData;
INT i;
ULONG i;
PRUNTIME_FUNCTION FunctionEntry;
DPRINT("Enter RtlWalkFrameChain\n");

View file

@ -43,7 +43,7 @@ BOOLEAN
NTAPI
LdrVerifyMappedImageMatchesChecksum(
IN PVOID BaseAddress,
IN ULONG ImageSize,
IN SIZE_T ImageSize,
IN ULONG FileLength)
{
#if 0
@ -192,7 +192,7 @@ RtlImageNtHeaderEx(IN ULONG Flags,
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 @@ RtlImageNtHeaderEx(IN ULONG Flags,
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 @@ RtlImageNtHeaderEx(IN ULONG Flags,
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 @@ RtlImageNtHeaderEx(IN ULONG Flags,
*OutHeaders = NtHeaders;
return STATUS_SUCCESS;
}
/*
* @implemented
*/

View file

@ -26,7 +26,7 @@ static __inline VOID
RtlpCopyParameterString(PWCHAR *Ptr,
PUNICODE_STRING Destination,
PUNICODE_STRING Source,
ULONG Size)
USHORT Size)
{
Destination->Length = Source->Length;
Destination->MaximumLength = Size ? Size : Source->MaximumLength;

View file

@ -99,7 +99,7 @@ RtlAnsiStringToUnicodeString(
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 @@ RtlCharToInteger(
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 @@ NTAPI
RtlInitAnsiString(IN OUT PANSI_STRING DestinationString,
IN PCSZ SourceString)
{
ULONG DestSize;
SIZE_T Size;
if(SourceString)
if (SourceString)
{
DestSize = strlen(SourceString);
DestinationString->Length = (USHORT)DestSize;
DestinationString->MaximumLength = (USHORT)DestSize + sizeof(CHAR);
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 @@ NTAPI
RtlInitAnsiStringEx(IN OUT PANSI_STRING DestinationString,
IN PCSZ SourceString)
{
ULONG DestSize;
SIZE_T Size;
if(SourceString)
if (SourceString)
{
DestSize = strlen(SourceString);
if (DestSize >= 0xFFFF) return STATUS_NAME_TOO_LONG;
DestinationString->Length = (USHORT)DestSize;
DestinationString->MaximumLength = (USHORT)DestSize + sizeof(CHAR);
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 @@ RtlInitString(
*/
VOID
NTAPI
RtlInitUnicodeString(IN OUT PUNICODE_STRING DestinationString,
IN PCWSTR SourceString)
RtlInitUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN PCWSTR SourceString)
{
ULONG DestSize;
SIZE_T Size;
if(SourceString)
if (SourceString)
{
DestSize = wcslen(SourceString) * sizeof(WCHAR);
DestinationString->Length = (USHORT)DestSize;
DestinationString->MaximumLength = (USHORT)DestSize + sizeof(WCHAR);
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 @@ RtlInitUnicodeString(IN OUT PUNICODE_STRING DestinationString,
*/
NTSTATUS
NTAPI
RtlInitUnicodeStringEx(OUT PUNICODE_STRING DestinationString,
IN PCWSTR SourceString)
RtlInitUnicodeStringEx(
OUT PUNICODE_STRING DestinationString,
IN PCWSTR SourceString)
{
ULONG DestSize;
SIZE_T Size;
if(SourceString)
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);
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 @@ NTSTATUS NTAPI RtlIntegerToChar(
CHAR buffer[33];
PCHAR pos;
CHAR digit;
ULONG len;
SIZE_T len;
if (base == 0)
{
@ -663,7 +663,7 @@ NTSTATUS NTAPI RtlIntegerToChar(
do
{
pos--;
digit = value % base;
digit = (CHAR)(value % base);
value = value / base;
if (digit < 10)
@ -734,8 +734,8 @@ RtlIntegerToUnicode(
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 @@ RtlUnicodeStringToInteger(
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 @@ RtlUnicodeStringToAnsiString(
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 @@ RtlOemStringToUnicodeString(
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 @@ RtlUnicodeStringToOemString(
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 @@ RtlOemStringToCountedUnicodeString(
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 @@ BOOLEAN
NTAPI
RtlEqualDomainName (
IN PUNICODE_STRING DomainName1,
IN PUNICODE_STRING DomainName2
)
IN PUNICODE_STRING DomainName2)
{
return RtlEqualComputerName(DomainName1, DomainName2);
}
@ -1483,8 +1478,7 @@ NTSTATUS
NTAPI
RtlGUIDFromString(
IN UNICODE_STRING *str,
OUT GUID* guid
)
OUT GUID* guid)
{
int i = 0;
const WCHAR *lpszCLSID = str->Buffer;
@ -1697,7 +1691,7 @@ RtlUnicodeStringToCountedOemString(
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 @@ RtlLargeIntegerToChar(
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 @@ RtlLargeIntegerToChar(
do
{
Pos--;
Digit = Val % Base;
Digit = (CHAR)(Val % Base);
Val = Val / Base;
if (Digit < 10)
@ -1873,7 +1866,7 @@ RtlUpcaseUnicodeStringToAnsiString(
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 @@ RtlUpcaseUnicodeStringToCountedOemString(
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 @@ RtlUpcaseUnicodeStringToOemString (
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 @@ RtlCreateUnicodeString(
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;
Size = (wcslen(Source) + 1) * sizeof(WCHAR);
if (Size > MAXUSHORT) return FALSE;
UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
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 @@ RtlAppendAsciizToString(
IN OUT PSTRING Destination,
IN PCSZ Source)
{
ULONG Length;
SIZE_T Size;
if (Source)
{
Length = (USHORT)strlen(Source);
Size = strlen(Source);
if (Destination->Length + Length > Destination->MaximumLength)
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 @@ NTAPI
RtlUpperString(PSTRING DestinationString,
PSTRING SourceString)
{
ULONG Length;
USHORT Length;
PCHAR Src, Dest;
Length = min(SourceString->Length,
@ -2502,20 +2495,20 @@ RtlFindCharInUnicodeString(
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 @@ RtlFindCharInUnicodeString(
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 @@ RtlFindCharInUnicodeString(
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;
j = 0;
while (search_idx < MatchString->Length / sizeof(WCHAR) &&
SearchString->Buffer[main_idx] != MatchString->Buffer[search_idx])
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 @@ RtlFindCharInUnicodeString(
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;
j = 0;
while (search_idx < MatchString->Length / sizeof(WCHAR) &&
SearchString->Buffer[main_idx] != MatchString->Buffer[search_idx])
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;
}
}