From 975d94d909d9414b8a1917476fd6a3cfd2b98782 Mon Sep 17 00:00:00 2001 From: Rafal Harabien Date: Sun, 9 Oct 2011 09:55:40 +0000 Subject: [PATCH] [RTL] - Make sure RtlInitUnicodeString(Ex) don't set odd length. Fixes ntdll:rtlstr winetest. svn path=/trunk/; revision=54061 --- reactos/lib/rtl/unicode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/reactos/lib/rtl/unicode.c b/reactos/lib/rtl/unicode.c index 32de447380f..8eb7b13c404 100644 --- a/reactos/lib/rtl/unicode.c +++ b/reactos/lib/rtl/unicode.c @@ -584,11 +584,12 @@ RtlInitUnicodeString( IN PCWSTR SourceString) { SIZE_T Size; + CONST SIZE_T MaxSize = (MAXUSHORT & ~1) - sizeof(WCHAR); // an even number if (SourceString) { Size = wcslen(SourceString) * sizeof(WCHAR); - if (Size > (MAXUSHORT - sizeof(WCHAR))) Size = MAXUSHORT - sizeof(WCHAR); + if (Size > MaxSize) Size = MaxSize; DestinationString->Length = (USHORT)Size; DestinationString->MaximumLength = (USHORT)Size + sizeof(WCHAR); } @@ -611,11 +612,12 @@ RtlInitUnicodeStringEx( IN PCWSTR SourceString) { SIZE_T Size; + CONST SIZE_T MaxSize = (MAXUSHORT & ~1) - sizeof(WCHAR); // an even number if (SourceString) { Size = wcslen(SourceString) * sizeof(WCHAR); - if (Size > (MAXUSHORT - sizeof(WCHAR))) return STATUS_NAME_TOO_LONG; + if (Size > MaxSize) return STATUS_NAME_TOO_LONG; DestinationString->Length = (USHORT)Size; DestinationString->MaximumLength = (USHORT)Size + sizeof(WCHAR); }