[RTL] Fix RtlValidateUnicodeString() regarding the tests and add some SAL annotations.
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Thu, 2 Jan 2020 20:10:42 +0000 (21:10 +0100)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Thu, 2 Jan 2020 20:11:28 +0000 (21:11 +0100)
sdk/lib/rtl/unicode.c

index 7d2470a..7f04540 100644 (file)
@@ -2541,22 +2541,24 @@ RtlDuplicateUnicodeString(
  */
 NTSTATUS
 NTAPI
-RtlValidateUnicodeString(IN ULONG Flags,
-                         IN PCUNICODE_STRING UnicodeString)
+RtlValidateUnicodeString(
+    _In_ ULONG Flags,
+    _In_ PCUNICODE_STRING String)
 {
-    /* currently no flags are supported! */
-    ASSERT(Flags == 0);
-
-    if ((Flags == 0) &&
-        ((UnicodeString == NULL) ||
-         ((UnicodeString->Length != 0) &&
-          (UnicodeString->Buffer != NULL) &&
-          ((UnicodeString->Length % sizeof(WCHAR)) == 0) &&
-          ((UnicodeString->MaximumLength % sizeof(WCHAR)) == 0) &&
-          (UnicodeString->MaximumLength >= UnicodeString->Length))))
-    {
-        /* a NULL pointer as a unicode string is considered to be a valid unicode
-           string! */
+    /* In Windows <= 2003 no flags are supported yet! */
+    if (Flags != 0)
+        return STATUS_INVALID_PARAMETER;
+
+    /* NOTE: a NULL Unicode string pointer is considered to be a valid one! */
+    if (String == NULL)
+    {
+        return STATUS_SUCCESS;
+    }
+    else if (!((String->Buffer == NULL) && (String->Length != 0 || String->MaximumLength != 0)) &&
+              (String->Length % sizeof(WCHAR) == 0) &&
+              (String->MaximumLength % sizeof(WCHAR) == 0) &&
+              (String->Length <= String->MaximumLength))
+    {
         return STATUS_SUCCESS;
     }
     else