qmgr: Don't dereference null pointers (clang)

André Hentschel nerv at dawncrow.de
Wed Jul 13 13:35:37 CDT 2011


makes sure This->files and This->jobs are not read while they are NULL
---
 dlls/qmgr/enum_files.c |   19 +++++++++++--------
 dlls/qmgr/enum_jobs.c  |   15 ++++++++-------
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/dlls/qmgr/enum_files.c b/dlls/qmgr/enum_files.c
index d7f36cd..21a59ff 100644
--- a/dlls/qmgr/enum_files.c
+++ b/dlls/qmgr/enum_files.c
@@ -188,7 +188,7 @@ HRESULT EnumBackgroundCopyFilesConstructor(LPVOID *ppObj, IBackgroundCopyJob2 *i
     This->indexFiles = 0;
     EnterCriticalSection(&job->cs);
     This->numFiles = list_count(&job->files);
-    This->files = NULL;
+
     if (This->numFiles > 0)
     {
         This->files = HeapAlloc(GetProcessHeap(), 0,
@@ -199,15 +199,18 @@ HRESULT EnumBackgroundCopyFilesConstructor(LPVOID *ppObj, IBackgroundCopyJob2 *i
             HeapFree(GetProcessHeap(), 0, This);
             return E_OUTOFMEMORY;
         }
-    }
 
-    i = 0;
-    LIST_FOR_EACH_ENTRY(file, &job->files, BackgroundCopyFileImpl, entryFromJob)
-    {
-        file->lpVtbl->AddRef((IBackgroundCopyFile *) file);
-        This->files[i] = (IBackgroundCopyFile *) file;
-        ++i;
+        i = 0;
+        LIST_FOR_EACH_ENTRY(file, &job->files, BackgroundCopyFileImpl, entryFromJob)
+        {
+            file->lpVtbl->AddRef((IBackgroundCopyFile *) file);
+            This->files[i] = (IBackgroundCopyFile *) file;
+            ++i;
+        }
     }
+    else
+        This->files = NULL;
+
     LeaveCriticalSection(&job->cs);
 
     *ppObj = &This->lpVtbl;
diff --git a/dlls/qmgr/enum_jobs.c b/dlls/qmgr/enum_jobs.c
index 85aca47..f34a197 100644
--- a/dlls/qmgr/enum_jobs.c
+++ b/dlls/qmgr/enum_jobs.c
@@ -195,17 +195,18 @@ HRESULT EnumBackgroundCopyJobsConstructor(LPVOID *ppObj,
             HeapFree(GetProcessHeap(), 0, This);
             return E_OUTOFMEMORY;
         }
+
+        i = 0;
+        LIST_FOR_EACH_ENTRY(job, &qmgr->jobs, BackgroundCopyJobImpl, entryFromQmgr)
+        {
+            IBackgroundCopyJob *iJob = (IBackgroundCopyJob *) job;
+            IBackgroundCopyJob_AddRef(iJob);
+            This->jobs[i++] = iJob;
+        }
     }
     else
         This->jobs = NULL;
 
-    i = 0;
-    LIST_FOR_EACH_ENTRY(job, &qmgr->jobs, BackgroundCopyJobImpl, entryFromQmgr)
-    {
-        IBackgroundCopyJob *iJob = (IBackgroundCopyJob *) job;
-        IBackgroundCopyJob_AddRef(iJob);
-        This->jobs[i++] = iJob;
-    }
     LeaveCriticalSection(&qmgr->cs);
 
     *ppObj = &This->lpVtbl;
-- 

Best Regards, André Hentschel



More information about the wine-patches mailing list