Don't add a terminating null character in RtlCopyString, if the destination buffer...
authorHartmut Birr <osexpert@googlemail.com>
Thu, 13 Jan 2005 20:53:35 +0000 (20:53 +0000)
committerHartmut Birr <osexpert@googlemail.com>
Thu, 13 Jan 2005 20:53:35 +0000 (20:53 +0000)
A ansi/unicode string doesn't need a terminating null character.

svn path=/trunk/; revision=13030

reactos/lib/rtl/unicode.c

index 00158fb..9905fc9 100644 (file)
@@ -2195,11 +2195,14 @@ RtlCopyString(
       return;
    }
 
-   copylen = min (DestinationString->MaximumLength - sizeof(CHAR),
+   copylen = min (DestinationString->MaximumLength,
                   SourceString->Length);
 
    memcpy(DestinationString->Buffer, SourceString->Buffer, copylen);
-   DestinationString->Buffer[copylen] = 0;
+   if (DestinationString->MaximumLength >= copylen + sizeof(CHAR))
+   {
+      DestinationString->Buffer[copylen] = 0;
+   }
    DestinationString->Length = copylen;
 }
 
@@ -2222,10 +2225,13 @@ RtlCopyUnicodeString(
       return;
    }
 
-   copylen = min (DestinationString->MaximumLength - sizeof(WCHAR),
+   copylen = min (DestinationString->MaximumLength,
                   SourceString->Length);
    memcpy(DestinationString->Buffer, SourceString->Buffer, copylen);
-   DestinationString->Buffer[copylen / sizeof(WCHAR)] = 0;
+   if (DestinationString->MaximumLength >= copylen + sizeof(WCHAR))
+   {
+     DestinationString->Buffer[copylen / sizeof(WCHAR)] = 0;
+   }
    DestinationString->Length = copylen;
 }