[WIN32K]
authorThomas Faber <thomas.faber@reactos.org>
Tue, 21 Oct 2014 12:43:15 +0000 (12:43 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Tue, 21 Oct 2014 12:43:15 +0000 (12:43 +0000)
- Remove bug-hiding list macros that accept NULL in LIST_ENTRYs.
CORE-8668 #resolve

svn path=/trunk/; revision=64865

reactos/win32ss/gdi/ntgdi/misc.h
reactos/win32ss/user/ntuser/cursoricon.c
reactos/win32ss/user/ntuser/desktop.c

index 3684f40..6fba126 100644 (file)
@@ -162,15 +162,3 @@ BOOL NTAPI W32kDosPathNameToNtPathName(PCWSTR, PUNICODE_STRING);
 
 #define ROUND_UP(n, align) \
     ROUND_DOWN(((ULONG)n) + (align) - 1, (align))
-
-#define LIST_FOR_EACH(elem, list, type, field) \
-    for ((elem) = CONTAINING_RECORD((list)->Flink, type, field); \
-         &(elem)->field != (list) && ((&((elem)->field)) != NULL); \
-         (elem) = CONTAINING_RECORD((elem)->field.Flink, type, field))
-
-#define LIST_FOR_EACH_SAFE(cursor, cursor2, list, type, field) \
-    for ((cursor) = CONTAINING_RECORD((list)->Flink, type, field), \
-         (cursor2) = CONTAINING_RECORD((cursor)->field.Flink, type, field); \
-         &(cursor)->field != (list); \
-         (cursor) = (cursor2), \
-         (cursor2) = CONTAINING_RECORD((cursor)->field.Flink, type, field))
index c8f89cf..68db687 100644 (file)
@@ -144,12 +144,16 @@ static BOOLEAN FASTCALL
 ReferenceCurIconByProcess(PCURICON_OBJECT CurIcon)
 {
     PPROCESSINFO Win32Process;
+    PLIST_ENTRY ListEntry;
     PCURICON_PROCESS Current;
 
     Win32Process = PsGetCurrentProcessWin32Process();
 
-    LIST_FOR_EACH(Current, &CurIcon->ProcessList, CURICON_PROCESS, ListEntry)
+    ListEntry = CurIcon->ProcessList.Flink;
+    while (ListEntry != &CurIcon->ProcessList)
     {
+        Current = CONTAINING_RECORD(ListEntry, CURICON_PROCESS, ListEntry);
+        ListEntry = ListEntry->Flink;
         if (Current->Process == Win32Process)
         {
             /* Already registered for this process */
@@ -173,10 +177,14 @@ PCURICON_OBJECT FASTCALL
 IntFindExistingCurIconObject(HMODULE hModule,
                              HRSRC hRsrc, LONG cx, LONG cy)
 {
+    PLIST_ENTRY ListEntry;
     PCURICON_OBJECT CurIcon;
 
-    LIST_FOR_EACH(CurIcon, &gCurIconList, CURICON_OBJECT, ListEntry)
+    ListEntry = gCurIconList.Flink;
+    while (ListEntry != &gCurIconList)
     {
+        CurIcon = CONTAINING_RECORD(ListEntry, CURICON_OBJECT, ListEntry);
+        ListEntry = ListEntry->Flink;
 
         // if (NT_SUCCESS(UserReferenceObjectByPointer(Object, TYPE_CURSOR))) // <- huh????
 //      UserReferenceObject(  CurIcon);
@@ -247,7 +255,8 @@ IntDestroyCurIconObject(PCURICON_OBJECT CurIcon, PPROCESSINFO ppi)
     PSYSTEM_CURSORINFO CurInfo;
     HBITMAP bmpMask, bmpColor;
     BOOLEAN Ret, bListEmpty, bFound = FALSE;
-    PCURICON_PROCESS Current = NULL;
+    PLIST_ENTRY ListEntry;
+    PCURICON_PROCESS Current;
 
     /* For handles created without any data (error handling) */
     if(IsListEmpty(&CurIcon->ProcessList))
@@ -255,8 +264,11 @@ IntDestroyCurIconObject(PCURICON_OBJECT CurIcon, PPROCESSINFO ppi)
 
     /* Now find this process in the list of processes referencing this object and
        remove it from that list */
-    LIST_FOR_EACH(Current, &CurIcon->ProcessList, CURICON_PROCESS, ListEntry)
+    ListEntry = CurIcon->ProcessList.Flink;
+    while (ListEntry != &CurIcon->ProcessList)
     {
+        Current = CONTAINING_RECORD(ListEntry, CURICON_PROCESS, ListEntry);
+        ListEntry = ListEntry->Flink;
         if (Current->Process == ppi)
         {
             bFound = TRUE;
index 69ab304..a8f0277 100644 (file)
@@ -806,12 +806,17 @@ HWND* FASTCALL
 UserBuildShellHookHwndList(PDESKTOP Desktop)
 {
    ULONG entries=0;
+   PLIST_ENTRY ListEntry;
    PSHELL_HOOK_WINDOW Current;
    HWND* list;
 
    /* FIXME: If we save nb elements in desktop, we dont have to loop to find nb entries */
-   LIST_FOR_EACH(Current, &Desktop->ShellHookWindows, SHELL_HOOK_WINDOW, ListEntry)
+   ListEntry = Desktop->ShellHookWindows.Flink;
+   while (ListEntry != &Desktop->ShellHookWindows)
+   {
+      ListEntry = ListEntry->Flink;
       entries++;
+   }
 
    if (!entries) return NULL;
 
@@ -820,8 +825,13 @@ UserBuildShellHookHwndList(PDESKTOP Desktop)
    {
       HWND* cursor = list;
 
-      LIST_FOR_EACH(Current, &Desktop->ShellHookWindows, SHELL_HOOK_WINDOW, ListEntry)
+      ListEntry = Desktop->ShellHookWindows.Flink;
+      while (ListEntry != &Desktop->ShellHookWindows)
+      {
+         Current = CONTAINING_RECORD(ListEntry, SHELL_HOOK_WINDOW, ListEntry);
+         ListEntry = ListEntry->Flink;
          *cursor++ = Current->hWnd;
+      }
 
       *cursor = NULL; /* Nullterm list */
    }
@@ -930,10 +940,14 @@ BOOL IntDeRegisterShellHookWindow(HWND hWnd)
 {
    PTHREADINFO pti = PsGetCurrentThreadWin32Thread();
    PDESKTOP Desktop = pti->rpdesk;
+   PLIST_ENTRY ListEntry;
    PSHELL_HOOK_WINDOW Current;
 
-   LIST_FOR_EACH(Current, &Desktop->ShellHookWindows, SHELL_HOOK_WINDOW, ListEntry)
+   ListEntry = Desktop->ShellHookWindows.Flink;
+   while (ListEntry != &Desktop->ShellHookWindows)
    {
+      Current = CONTAINING_RECORD(ListEntry, SHELL_HOOK_WINDOW, ListEntry);
+      ListEntry = ListEntry->Flink;
       if (Current->hWnd == hWnd)
       {
          RemoveEntryList(&Current->ListEntry);