https://git.reactos.org/?p=reactos.git;a=commitdiff;h=45aa17938689258e402470f11ea845610696cc29

commit 45aa17938689258e402470f11ea845610696cc29
Author:     Serge Gautherie <[email protected]>
AuthorDate: Sun Feb 18 14:06:23 2018 +0100
Commit:     Thomas Faber <[email protected]>
CommitDate: Sun Feb 18 14:14:56 2018 +0100

    [KMTESTS:IO] Fix a Clang-Cl warning about NameLength
    
    "warning: variable 'NameLength' is used uninitialized whenever 'if' 
condition is false [-Wsometimes-uninitialized]"
    
    CORE-14306
---
 modules/rostests/kmtests/ntos_io/IoFilesystem.c | 62 +++++++++++++++----------
 1 file changed, 37 insertions(+), 25 deletions(-)

diff --git a/modules/rostests/kmtests/ntos_io/IoFilesystem.c 
b/modules/rostests/kmtests/ntos_io/IoFilesystem.c
index c974b8cf64..ff3a502f53 100644
--- a/modules/rostests/kmtests/ntos_io/IoFilesystem.c
+++ b/modules/rostests/kmtests/ntos_io/IoFilesystem.c
@@ -27,12 +27,13 @@ QueryFileInfo(
         Buffer = KmtAllocateGuarded(*Length);
         if (skip(Buffer != NULL, "Failed to allocate %Iu bytes\n", *Length))
             return STATUS_INSUFFICIENT_RESOURCES;
+
+        RtlFillMemory(Buffer, *Length, 0xdd);
     }
     else
     {
         Buffer = NULL;
     }
-    RtlFillMemory(Buffer, *Length, 0xDD);
     RtlFillMemory(&IoStatus, sizeof(IoStatus), 0x55);
     _SEH2_TRY
     {
@@ -55,8 +56,16 @@ QueryFileInfo(
         ok_eq_hex(Status, STATUS_SUCCESS);
         Status = IoStatus.Status;
     }
+
     *Length = IoStatus.Information;
-    *Info = Buffer;
+    if (NT_SUCCESS(Status))
+    {
+        *Info = Buffer;
+    }
+    else if (Buffer)
+    {
+        KmtFreeGuarded(Buffer);
+    }
     return Status;
 }
 
@@ -140,33 +149,35 @@ TestAllInformation(VOID)
     Length = FIELD_OFFSET(FILE_ALL_INFORMATION, NameInformation.FileName) + 
MAX_PATH * sizeof(WCHAR);
     Status = QueryFileInfo(FileHandle, (PVOID*)&FileAllInfo, &Length, 
FileAllInformation);
     ok_eq_hex(Status, STATUS_SUCCESS);
-    if (!skip(NT_SUCCESS(Status) && FileAllInfo != NULL, "No info\n"))
+    if (skip(NT_SUCCESS(Status) && FileAllInfo != NULL, "No info\n"))
     {
-        NameLength = FileAllInfo->NameInformation.FileNameLength;
-        ok_eq_size(Length, FIELD_OFFSET(FILE_ALL_INFORMATION, 
NameInformation.FileName) + NameLength);
-        Name = ExAllocatePoolWithTag(PagedPool, NameLength + 
sizeof(UNICODE_NULL), 'sFmK');
-        if (!skip(Name != NULL, "Could not allocate %lu bytes\n", NameLength + 
(ULONG)sizeof(UNICODE_NULL)))
+        goto NoInfo;
+    }
+
+    NameLength = FileAllInfo->NameInformation.FileNameLength;
+    ok_eq_size(Length, FIELD_OFFSET(FILE_ALL_INFORMATION, 
NameInformation.FileName) + NameLength);
+    Name = ExAllocatePoolWithTag(PagedPool, NameLength + sizeof(UNICODE_NULL), 
'sFmK');
+    if (!skip(Name != NULL, "Could not allocate %lu bytes\n", NameLength + 
(ULONG)sizeof(UNICODE_NULL)))
+    {
+        RtlCopyMemory(Name,
+                      FileAllInfo->NameInformation.FileName,
+                      NameLength);
+        Name[NameLength / sizeof(WCHAR)] = UNICODE_NULL;
+        ok(Name[0] == L'\\', "Name is %ls, expected first char to be \\\n", 
Name);
+        ok(NameLength >= Ntoskrnl.Length + sizeof(WCHAR), "NameLength %lu too 
short\n", NameLength);
+        if (NameLength >= Ntoskrnl.Length)
         {
-            RtlCopyMemory(Name,
-                          FileAllInfo->NameInformation.FileName,
-                          NameLength);
-            Name[NameLength / sizeof(WCHAR)] = UNICODE_NULL;
-            ok(Name[0] == L'\\', "Name is %ls, expected first char to be 
\\\n", Name);
-            ok(NameLength >= Ntoskrnl.Length + sizeof(WCHAR), "NameLength %lu 
too short\n", NameLength);
-            if (NameLength >= Ntoskrnl.Length)
-            {
-                NamePart.Buffer = Name + (NameLength - Ntoskrnl.Length) / 
sizeof(WCHAR);
-                NamePart.Length = Ntoskrnl.Length;
-                NamePart.MaximumLength = NamePart.Length;
-                ok(RtlEqualUnicodeString(&NamePart, &Ntoskrnl, TRUE),
-                   "Name ends in '%wZ', expected %wZ\n", &NamePart, &Ntoskrnl);
-            }
-            ExFreePoolWithTag(Name, 'sFmK');
+            NamePart.Buffer = Name + (NameLength - Ntoskrnl.Length) / 
sizeof(WCHAR);
+            NamePart.Length = Ntoskrnl.Length;
+            NamePart.MaximumLength = NamePart.Length;
+            ok(RtlEqualUnicodeString(&NamePart, &Ntoskrnl, TRUE),
+               "Name ends in '%wZ', expected %wZ\n", &NamePart, &Ntoskrnl);
         }
-        ok(FileAllInfo->NameInformation.FileName[NameLength / sizeof(WCHAR)] 
== 0xdddd,
-           "Char past FileName is %x\n",
-           FileAllInfo->NameInformation.FileName[NameLength / sizeof(WCHAR)]);
+        ExFreePoolWithTag(Name, 'sFmK');
     }
+    ok(FileAllInfo->NameInformation.FileName[NameLength / sizeof(WCHAR)] == 
0xdddd,
+       "Char past FileName is %x\n",
+       FileAllInfo->NameInformation.FileName[NameLength / sizeof(WCHAR)]);
     if (FileAllInfo)
         KmtFreeGuarded(FileAllInfo);
 
@@ -210,6 +221,7 @@ TestAllInformation(VOID)
     if (FileAllInfo)
         KmtFreeGuarded(FileAllInfo);
 
+NoInfo:
     Status = ObCloseHandle(FileHandle, KernelMode);
     ok_eq_hex(Status, STATUS_SUCCESS);
 }

Reply via email to