- 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;
}
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));
*lParamPacked = (LPARAM)PackedData;
}
@ -375,6 +380,7 @@ UnpackParam(LPARAM lParamPacked, UINT Msg, WPARAM wParam, LPARAM lParam, BOOL No
{
PMSGMEMORY MsgMemoryEntry;
MsgMemoryEntry = FindMsgMemory(Msg);
ASSERT(MsgMemoryEntry);
if (MsgMemoryEntry->Size < 0)
{
/* Keep previous behavior */
@ -587,7 +593,7 @@ IntCallWndProcRet ( PWND Window, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lPar
CWPR.message = Msg;
CWPR.wParam = wParam;
CWPR.lParam = lParam;
CWPR.lResult = *uResult;
CWPR.lResult = uResult ? (*uResult) : 0;
co_HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, SameThread, (LPARAM)&CWPR );
}
@ -608,7 +614,7 @@ IntDispatchMessage(PMSG pMsg)
pti = PsGetCurrentThreadWin32Thread();
if ( Window->head.pti != pti)
if ( Window && Window->head.pti != pti)
{
EngSetLastError( ERROR_MESSAGE_SYNC_ONLY );
return 0;
@ -2050,7 +2056,7 @@ NtUserMessageCall( HWND hWnd,
{
case FNID_DEFWINDOWPROC:
/* Validate input */
if (hWnd && (hWnd != INVALID_HANDLE_VALUE))
if (hWnd)
{
Window = UserGetWindowObject(hWnd);
if (!Window)
@ -2058,11 +2064,12 @@ NtUserMessageCall( HWND hWnd,
UserLeave();
return FALSE;
}
UserRefObjectCo(Window, &Ref);
}
UserRefObjectCo(Window, &Ref);
lResult = IntDefWindowProc(Window, Msg, wParam, lParam, Ansi);
Ret = TRUE;
UserDerefObjectCo(Window);
if (hWnd)
UserDerefObjectCo(Window);
break;
case FNID_SENDNOTIFYMESSAGE:
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
set the layout explicitly.
*/
if ( Class && Class->fnid != FNID_DIALOG)
if ( Class->fnid != FNID_DIALOG)
{
PPROCESSINFO ppi = PsGetCurrentProcessWin32Process();
if (ppi->dwLayout & LAYOUT_RTL)
@ -2170,6 +2170,9 @@ co_UserCreateWindowEx(CREATESTRUCTW* Cs,
if (Window->ExStyle & WS_EX_MDICHILD)
{
ASSERT(ParentWindow);
if(!ParentWindow)
goto cleanup;
co_IntSendMessage(UserHMGetHandle(ParentWindow), WM_MDIREFRESHMENU, 0, 0);
/* ShowWindow won't activate child windows */
co_WinPosSetWindowPos(Window, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
@ -2291,20 +2294,19 @@ NtUserCreateWindowEx(
lstrWindowName.Buffer = NULL;
lstrClassName.Buffer = NULL;
/* Check if we got a Window name */
if (plstrWindowName)
ASSERT(plstrWindowName);
/* Copy the window name to kernel mode */
Status = ProbeAndCaptureLargeString(&lstrWindowName, plstrWindowName);
if (!NT_SUCCESS(Status))
{
/* Copy the string to kernel mode */
Status = ProbeAndCaptureLargeString(&lstrWindowName, plstrWindowName);
if (!NT_SUCCESS(Status))
{
ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
SetLastNtError(Status);
return NULL;
}
plstrWindowName = &lstrWindowName;
ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
SetLastNtError(Status);
return NULL;
}
plstrWindowName = &lstrWindowName;
/* Check if the class is an atom */
if (IS_ATOM(plstrClassName))
{

View file

@ -162,6 +162,12 @@ co_WinPosArrangeIconicWindows(PWND parent)
ASSERT_REFS_CO(parent);
/* Check if we found any children */
if(List == NULL)
{
return 0;
}
IntGetClientRect( parent, &rectParent );
x = rectParent.left;
y = rectParent.bottom;
@ -693,15 +699,14 @@ co_WinPosDoWinPosChanging(PWND Window,
*/
static
HWND FASTCALL
WinPosDoOwnedPopups(HWND hWnd, HWND hWndInsertAfter)
WinPosDoOwnedPopups(PWND Window, HWND hWndInsertAfter)
{
HWND *List = NULL;
HWND Owner;
LONG Style;
PWND Window ,DesktopWindow, ChildObject;
PWND DesktopWindow, ChildObject;
int i;
Window = UserGetWindowObject(hWnd);
Owner = Window->spwndOwner ? Window->spwndOwner->head.h : NULL;
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];
if (hWndLocalPrev == hWndInsertAfter)
break;
@ -757,7 +762,7 @@ WinPosDoOwnedPopups(HWND hWnd, HWND hWndInsertAfter)
{
PWND Wnd;
if (List[i] == hWnd)
if (List[i] == Window->head.h)
break;
if (!(Wnd = UserGetWindowObject(List[i])))
@ -896,11 +901,15 @@ WinPosFixupFlags(WINDOWPOS *WinPos, PWND Wnd)
&& HWND_NOTOPMOST != WinPos->hwndInsertAfter
&& HWND_BOTTOM != WinPos->hwndInsertAfter)
{
PWND InsAfterWnd, Parent = Wnd->spwndParent;
PWND InsAfterWnd;
InsAfterWnd = UserGetWindowObject(WinPos->hwndInsertAfter);
if(!InsAfterWnd)
{
return TRUE;
}
if (InsAfterWnd && UserGetAncestor(InsAfterWnd, GA_PARENT) != Parent)
if (InsAfterWnd->spwndParent != Wnd->spwndParent)
{
return FALSE;
}
@ -995,7 +1004,7 @@ co_WinPosSetWindowPos(
SWP_NOZORDER &&
Ancestor && Ancestor->head.h == IntGetDesktopWindow() )
{
WinPos.hwndInsertAfter = WinPosDoOwnedPopups(WinPos.hwnd, WinPos.hwndInsertAfter);
WinPos.hwndInsertAfter = WinPosDoOwnedPopups(Window, WinPos.hwndInsertAfter);
}
if (!(WinPos.flags & SWP_NOREDRAW))
@ -1604,9 +1613,8 @@ co_WinPosSearchChildren(
return pwndChild;
}
}
ExFreePool(List);
}
ExFreePool(List);
}
*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++)
{
PWND pwnd;
USER_REFERENCE_ENTRY Ref;
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.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.x,
winpos->pos.y,
winpos->pos.cx,
winpos->pos.cy,
winpos->pos.flags);
UserDerefObjectCo(pwnd);
}
ExFreePoolWithTag(pDWP->acvr, USERTAG_SWP);
UserDereferenceObject(pDWP);