- Fix several issues detected by static code analysis

svn path=/trunk/; revision=53732
This commit is contained in:
Giannis Adamopoulos 2011-09-18 12:33:38 +00:00
parent 81495a4e8f
commit 922f076616
3 changed files with 56 additions and 28 deletions

View file

@ -334,6 +334,11 @@ PackParam(LPARAM *lParamPacked, UINT Msg, WPARAM wParam, LPARAM lParam, BOOL Non
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
PackedData = ExAllocatePoolWithTag(NonPagedPool, size, TAG_MSG); PackedData = ExAllocatePoolWithTag(NonPagedPool, size, TAG_MSG);
if (PackedData == NULL)
{
ERR("Not enough memory to pack lParam\n");
return STATUS_NO_MEMORY;
}
RtlCopyMemory(PackedData, (PVOID)lParam, MsgMemorySize(MsgMemoryEntry, wParam, lParam)); RtlCopyMemory(PackedData, (PVOID)lParam, MsgMemorySize(MsgMemoryEntry, wParam, lParam));
*lParamPacked = (LPARAM)PackedData; *lParamPacked = (LPARAM)PackedData;
} }
@ -375,6 +380,7 @@ UnpackParam(LPARAM lParamPacked, UINT Msg, WPARAM wParam, LPARAM lParam, BOOL No
{ {
PMSGMEMORY MsgMemoryEntry; PMSGMEMORY MsgMemoryEntry;
MsgMemoryEntry = FindMsgMemory(Msg); MsgMemoryEntry = FindMsgMemory(Msg);
ASSERT(MsgMemoryEntry);
if (MsgMemoryEntry->Size < 0) if (MsgMemoryEntry->Size < 0)
{ {
/* Keep previous behavior */ /* Keep previous behavior */
@ -587,7 +593,7 @@ IntCallWndProcRet ( PWND Window, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lPar
CWPR.message = Msg; CWPR.message = Msg;
CWPR.wParam = wParam; CWPR.wParam = wParam;
CWPR.lParam = lParam; CWPR.lParam = lParam;
CWPR.lResult = *uResult; CWPR.lResult = uResult ? (*uResult) : 0;
co_HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, SameThread, (LPARAM)&CWPR ); co_HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, SameThread, (LPARAM)&CWPR );
} }
@ -608,7 +614,7 @@ IntDispatchMessage(PMSG pMsg)
pti = PsGetCurrentThreadWin32Thread(); pti = PsGetCurrentThreadWin32Thread();
if ( Window->head.pti != pti) if ( Window && Window->head.pti != pti)
{ {
EngSetLastError( ERROR_MESSAGE_SYNC_ONLY ); EngSetLastError( ERROR_MESSAGE_SYNC_ONLY );
return 0; return 0;
@ -2050,7 +2056,7 @@ NtUserMessageCall( HWND hWnd,
{ {
case FNID_DEFWINDOWPROC: case FNID_DEFWINDOWPROC:
/* Validate input */ /* Validate input */
if (hWnd && (hWnd != INVALID_HANDLE_VALUE)) if (hWnd)
{ {
Window = UserGetWindowObject(hWnd); Window = UserGetWindowObject(hWnd);
if (!Window) if (!Window)
@ -2058,11 +2064,12 @@ NtUserMessageCall( HWND hWnd,
UserLeave(); UserLeave();
return FALSE; return FALSE;
} }
UserRefObjectCo(Window, &Ref);
} }
UserRefObjectCo(Window, &Ref);
lResult = IntDefWindowProc(Window, Msg, wParam, lParam, Ansi); lResult = IntDefWindowProc(Window, Msg, wParam, lParam, Ansi);
Ret = TRUE; Ret = TRUE;
UserDerefObjectCo(Window); if (hWnd)
UserDerefObjectCo(Window);
break; break;
case FNID_SENDNOTIFYMESSAGE: case FNID_SENDNOTIFYMESSAGE:
Ret = UserSendNotifyMessage(hWnd, Msg, wParam, lParam); Ret = UserSendNotifyMessage(hWnd, Msg, wParam, lParam);

View file

@ -1591,7 +1591,7 @@ PWND FASTCALL IntCreateWindow(CREATESTRUCTW* Cs,
Dialog boxes and message boxes do not inherit layout, so you must Dialog boxes and message boxes do not inherit layout, so you must
set the layout explicitly. set the layout explicitly.
*/ */
if ( Class && Class->fnid != FNID_DIALOG) if ( Class->fnid != FNID_DIALOG)
{ {
PPROCESSINFO ppi = PsGetCurrentProcessWin32Process(); PPROCESSINFO ppi = PsGetCurrentProcessWin32Process();
if (ppi->dwLayout & LAYOUT_RTL) if (ppi->dwLayout & LAYOUT_RTL)
@ -2170,6 +2170,9 @@ co_UserCreateWindowEx(CREATESTRUCTW* Cs,
if (Window->ExStyle & WS_EX_MDICHILD) if (Window->ExStyle & WS_EX_MDICHILD)
{ {
ASSERT(ParentWindow);
if(!ParentWindow)
goto cleanup;
co_IntSendMessage(UserHMGetHandle(ParentWindow), WM_MDIREFRESHMENU, 0, 0); co_IntSendMessage(UserHMGetHandle(ParentWindow), WM_MDIREFRESHMENU, 0, 0);
/* ShowWindow won't activate child windows */ /* ShowWindow won't activate child windows */
co_WinPosSetWindowPos(Window, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE); co_WinPosSetWindowPos(Window, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
@ -2291,20 +2294,19 @@ NtUserCreateWindowEx(
lstrWindowName.Buffer = NULL; lstrWindowName.Buffer = NULL;
lstrClassName.Buffer = NULL; lstrClassName.Buffer = NULL;
/* Check if we got a Window name */ ASSERT(plstrWindowName);
if (plstrWindowName)
/* Copy the window name to kernel mode */
Status = ProbeAndCaptureLargeString(&lstrWindowName, plstrWindowName);
if (!NT_SUCCESS(Status))
{ {
/* Copy the string to kernel mode */ ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
Status = ProbeAndCaptureLargeString(&lstrWindowName, plstrWindowName); SetLastNtError(Status);
if (!NT_SUCCESS(Status)) return NULL;
{
ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
SetLastNtError(Status);
return NULL;
}
plstrWindowName = &lstrWindowName;
} }
plstrWindowName = &lstrWindowName;
/* Check if the class is an atom */ /* Check if the class is an atom */
if (IS_ATOM(plstrClassName)) if (IS_ATOM(plstrClassName))
{ {

View file

@ -162,6 +162,12 @@ co_WinPosArrangeIconicWindows(PWND parent)
ASSERT_REFS_CO(parent); ASSERT_REFS_CO(parent);
/* Check if we found any children */
if(List == NULL)
{
return 0;
}
IntGetClientRect( parent, &rectParent ); IntGetClientRect( parent, &rectParent );
x = rectParent.left; x = rectParent.left;
y = rectParent.bottom; y = rectParent.bottom;
@ -693,15 +699,14 @@ co_WinPosDoWinPosChanging(PWND Window,
*/ */
static static
HWND FASTCALL HWND FASTCALL
WinPosDoOwnedPopups(HWND hWnd, HWND hWndInsertAfter) WinPosDoOwnedPopups(PWND Window, HWND hWndInsertAfter)
{ {
HWND *List = NULL; HWND *List = NULL;
HWND Owner; HWND Owner;
LONG Style; LONG Style;
PWND Window ,DesktopWindow, ChildObject; PWND DesktopWindow, ChildObject;
int i; int i;
Window = UserGetWindowObject(hWnd);
Owner = Window->spwndOwner ? Window->spwndOwner->head.h : NULL; Owner = Window->spwndOwner ? Window->spwndOwner->head.h : NULL;
Style = Window->style; Style = Window->style;
@ -732,7 +737,7 @@ WinPosDoOwnedPopups(HWND hWnd, HWND hWndInsertAfter)
} }
} }
} }
if (List[i] != hWnd) if (List[i] != Window->head.h)
hWndLocalPrev = List[i]; hWndLocalPrev = List[i];
if (hWndLocalPrev == hWndInsertAfter) if (hWndLocalPrev == hWndInsertAfter)
break; break;
@ -757,7 +762,7 @@ WinPosDoOwnedPopups(HWND hWnd, HWND hWndInsertAfter)
{ {
PWND Wnd; PWND Wnd;
if (List[i] == hWnd) if (List[i] == Window->head.h)
break; break;
if (!(Wnd = UserGetWindowObject(List[i]))) if (!(Wnd = UserGetWindowObject(List[i])))
@ -896,11 +901,15 @@ WinPosFixupFlags(WINDOWPOS *WinPos, PWND Wnd)
&& HWND_NOTOPMOST != WinPos->hwndInsertAfter && HWND_NOTOPMOST != WinPos->hwndInsertAfter
&& HWND_BOTTOM != WinPos->hwndInsertAfter) && HWND_BOTTOM != WinPos->hwndInsertAfter)
{ {
PWND InsAfterWnd, Parent = Wnd->spwndParent; PWND InsAfterWnd;
InsAfterWnd = UserGetWindowObject(WinPos->hwndInsertAfter); InsAfterWnd = UserGetWindowObject(WinPos->hwndInsertAfter);
if(!InsAfterWnd)
{
return TRUE;
}
if (InsAfterWnd && UserGetAncestor(InsAfterWnd, GA_PARENT) != Parent) if (InsAfterWnd->spwndParent != Wnd->spwndParent)
{ {
return FALSE; return FALSE;
} }
@ -995,7 +1004,7 @@ co_WinPosSetWindowPos(
SWP_NOZORDER && SWP_NOZORDER &&
Ancestor && Ancestor->head.h == IntGetDesktopWindow() ) Ancestor && Ancestor->head.h == IntGetDesktopWindow() )
{ {
WinPos.hwndInsertAfter = WinPosDoOwnedPopups(WinPos.hwnd, WinPos.hwndInsertAfter); WinPos.hwndInsertAfter = WinPosDoOwnedPopups(Window, WinPos.hwndInsertAfter);
} }
if (!(WinPos.flags & SWP_NOREDRAW)) if (!(WinPos.flags & SWP_NOREDRAW))
@ -1604,9 +1613,8 @@ co_WinPosSearchChildren(
return pwndChild; return pwndChild;
} }
} }
ExFreePool(List);
} }
ExFreePool(List);
} }
*HitTest = co_IntSendMessage(ScopeWin->head.h, WM_NCHITTEST, 0, *HitTest = co_IntSendMessage(ScopeWin->head.h, WM_NCHITTEST, 0,
@ -1756,17 +1764,28 @@ BOOL FASTCALL IntEndDeferWindowPosEx( HDWP hdwp )
for (i = 0, winpos = pDWP->acvr; res && i < pDWP->ccvr; i++, winpos++) for (i = 0, winpos = pDWP->acvr; res && i < pDWP->ccvr; i++, winpos++)
{ {
PWND pwnd;
USER_REFERENCE_ENTRY Ref;
TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n", TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
winpos->pos.hwnd, winpos->pos.hwndInsertAfter, winpos->pos.x, winpos->pos.y, winpos->pos.hwnd, winpos->pos.hwndInsertAfter, winpos->pos.x, winpos->pos.y,
winpos->pos.cx, winpos->pos.cy, winpos->pos.flags); winpos->pos.cx, winpos->pos.cy, winpos->pos.flags);
pwnd = UserGetWindowObject(winpos->pos.hwnd);
if(!pwnd)
continue;
res = co_WinPosSetWindowPos( UserGetWindowObject(winpos->pos.hwnd), UserRefObjectCo(pwnd, &Ref);
res = co_WinPosSetWindowPos( pwnd,
winpos->pos.hwndInsertAfter, winpos->pos.hwndInsertAfter,
winpos->pos.x, winpos->pos.x,
winpos->pos.y, winpos->pos.y,
winpos->pos.cx, winpos->pos.cx,
winpos->pos.cy, winpos->pos.cy,
winpos->pos.flags); winpos->pos.flags);
UserDerefObjectCo(pwnd);
} }
ExFreePoolWithTag(pDWP->acvr, USERTAG_SWP); ExFreePoolWithTag(pDWP->acvr, USERTAG_SWP);
UserDereferenceObject(pDWP); UserDereferenceObject(pDWP);