Fixing another memory crash bug this time for GetFourCCCodes

svn path=/trunk/; revision=26860
This commit is contained in:
Magnus Olsen 2007-05-21 20:51:55 +00:00
parent 3893f07116
commit d746c66d94
2 changed files with 21 additions and 16 deletions

View file

@ -146,28 +146,31 @@ HRESULT WINAPI
Main_DirectDraw_GetFourCCCodes(LPDIRECTDRAW7 iface, LPDWORD lpNumCodes, LPDWORD lpCodes) Main_DirectDraw_GetFourCCCodes(LPDIRECTDRAW7 iface, LPDWORD lpNumCodes, LPDWORD lpCodes)
{ {
LPDDRAWI_DIRECTDRAW_INT This = (LPDDRAWI_DIRECTDRAW_INT)iface; LPDDRAWI_DIRECTDRAW_INT This = (LPDDRAWI_DIRECTDRAW_INT)iface;
HRESULT retVal = DD_OK;
DX_WINDBG_trace(); DX_WINDBG_trace();
/* FIXME protect with SEH or something else if lpCodes or lpNumCodes for bad user pointers */ /* FIXME protect with SEH or something else if lpCodes or lpNumCodes for bad user pointers */
EnterCriticalSection(&ddcs); EnterCriticalSection(&ddcs);
if(!lpNumCodes) if(!lpNumCodes)
{ {
LeaveCriticalSection(&ddcs); retVal = DDERR_INVALIDPARAMS;
return DDERR_INVALIDPARAMS; }
} else
{
if(lpCodes) if ((lpCodes) && (*lpCodes))
{ {
memcpy(lpCodes, This->lpLcl->lpGbl->lpdwFourCC, sizeof(DWORD)* min(This->lpLcl->lpGbl->dwNumFourCC, *lpNumCodes)); memcpy(lpCodes, This->lpLcl->lpGbl->lpdwFourCC, sizeof(DWORD)* min(This->lpLcl->lpGbl->dwNumFourCC, *lpNumCodes));
} }
else else
{ {
*lpNumCodes = This->lpLcl->lpGbl->dwNumFourCC; *lpNumCodes = This->lpLcl->lpGbl->dwNumFourCC;
} }
}
LeaveCriticalSection(&ddcs); LeaveCriticalSection(&ddcs);
return DD_OK; return retVal;
} }
HRESULT WINAPI HRESULT WINAPI

View file

@ -188,7 +188,7 @@ StartDirectDraw(LPDIRECTDRAW iface, LPGUID lpGuid, BOOL reenable)
if (reenable == FALSE) if (reenable == FALSE)
{ {
if (This->lpLink == NULL) if ((!IsBadReadPtr(This->lpLink,sizeof(LPDIRECTDRAW))) && (This->lpLink == NULL))
{ {
RtlZeroMemory(&ddgbl, sizeof(DDRAWI_DIRECTDRAW_GBL)); RtlZeroMemory(&ddgbl, sizeof(DDRAWI_DIRECTDRAW_GBL));
This->lpLcl->lpGbl->dwRefCnt++; This->lpLcl->lpGbl->dwRefCnt++;
@ -471,6 +471,8 @@ StartDirectDrawHal(LPDIRECTDRAW iface, BOOL reenable)
return DD_FALSE; return DD_FALSE;
} }
DX_STUB_str("Here\n");
/* Alloc mpFourCC */ /* Alloc mpFourCC */
mpFourCC = NULL; mpFourCC = NULL;
if (mHALInfo.ddCaps.dwNumFourCCCodes > 0 ) if (mHALInfo.ddCaps.dwNumFourCCCodes > 0 )