X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=reactos%2Flib%2Frtl%2Funicode.c;h=9b29db30cf4b40e1b42b333ff04ff3c9d0789b42;hp=a988c5848c1fd538fe408ae01b05b33fdbf2df22;hb=484ec5bcf75d8f5811020a7c3f0474d6446f2dfe;hpb=7d203ec76d5c642d2bbd31716b73699774ec87a0 diff --git a/reactos/lib/rtl/unicode.c b/reactos/lib/rtl/unicode.c index a988c5848c1..9b29db30cf4 100644 --- a/reactos/lib/rtl/unicode.c +++ b/reactos/lib/rtl/unicode.c @@ -75,15 +75,15 @@ RtlAnsiStringToUnicodeString( if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2; UniDest->Length = (USHORT)Length - sizeof(WCHAR); - if (AllocateDestinationString == TRUE) + if (AllocateDestinationString) { UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR); UniDest->MaximumLength = Length; if (!UniDest->Buffer) return STATUS_NO_MEMORY; } - else if (Length >= UniDest->MaximumLength) + else if (UniDest->Length >= UniDest->MaximumLength) { - return STATUS_BUFFER_TOO_SMALL; + return STATUS_BUFFER_OVERFLOW; } Status = RtlMultiByteToUnicodeN(UniDest->Buffer, @@ -92,9 +92,13 @@ RtlAnsiStringToUnicodeString( AnsiSource->Buffer, AnsiSource->Length); - if (!NT_SUCCESS(Status) && AllocateDestinationString) + if (!NT_SUCCESS(Status)) { - RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR); + if (AllocateDestinationString) + { + RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR); + UniDest->Buffer = NULL; + } return Status; }