Author: fireball
Date: Sat Jan 17 01:44:28 2009
New Revision: 38808
URL:
http://svn.reactos.org/svn/reactos?rev=38808&view=rev
Log:
- RtlUnicodeStringToCountedOemString improvements:
* Fix zero-sized input string handling, result would be error instead of success and zero
output string.
* If destination string's MaximumLength and Length are equal, it's not an
erroneous situation (in fact, a very common situation).
* Add comments.
Modified:
trunk/reactos/lib/rtl/unicode.c
Modified: trunk/reactos/lib/rtl/unicode.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/unicode.c?rev=3880…
==============================================================================
--- trunk/reactos/lib/rtl/unicode.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/unicode.c [iso-8859-1] Sat Jan 17 01:44:28 2009
@@ -1492,38 +1492,47 @@
PAGED_CODE_RTL();
+ /* Calculate size of the string */
Length = RtlUnicodeStringToCountedOemSize(UniSource);
+ /* If it's 0 then zero out dest string and return */
if (!Length)
{
RtlZeroMemory(OemDest, sizeof(OEM_STRING));
- }
-
+ return STATUS_SUCCESS;
+ }
+
+ /* Check if length is a sane value */
if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
+ /* Store it in dest string */
OemDest->Length = (USHORT)Length;
+ /* If we're asked to alloc the string - do so */
if (AllocateDestinationString)
{
OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
OemDest->MaximumLength = Length;
if (!OemDest->Buffer) return STATUS_NO_MEMORY;
}
- else if (OemDest->Length >= OemDest->MaximumLength)
+ else if (OemDest->Length > OemDest->MaximumLength)
{
return STATUS_BUFFER_OVERFLOW;
}
+ /* Do the conversion */
Status = RtlUnicodeToOemN(OemDest->Buffer,
OemDest->Length,
&Index,
UniSource->Buffer,
UniSource->Length);
- /* FIXME: Special check needed and return STATUS_UNMAPPABLE_CHARACTER */
+ /* FIXME: Check if everything mapped correctly and
+ * return STATUS_UNMAPPABLE_CHARACTER */
if (!NT_SUCCESS(Status) && AllocateDestinationString)
{
+ /* Conversion failed, free dest string and return status code */
RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
OemDest->Buffer = NULL;
return Status;