Fixed small buffer overruns and other minor bugs that were found by VS2008 code analysis

Added a check on both video plugins to prevent crashing when Memory_GetPtr retuns null pointer at ExecuteDisplayList  (invalid address? Dave Mirra BMX 2 crashes there ...)

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1179 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
drkiiraziel 2008-11-15 02:30:29 +00:00
parent ab1774b28a
commit 9a4dc4e810
5 changed files with 39 additions and 29 deletions

View File

@ -54,23 +54,28 @@ static void ExecuteDisplayList(u32 address, u32 size)
u8* old_pVideoData = g_pVideoData; u8* old_pVideoData = g_pVideoData;
u8* startAddress = Memory_GetPtr(address); u8* startAddress = Memory_GetPtr(address);
g_pVideoData = startAddress;
// temporarily swap dl and non-dl(small "hack" for the stats) //Avoid the crash if Memory_GetPtr failed ..
Statistics::SwapDL(); if (startAddress!=0)
{
g_pVideoData = startAddress;
while((u32)(g_pVideoData - startAddress) < size) // temporarily swap dl and non-dl(small "hack" for the stats)
{ Statistics::SwapDL();
Decode();
}
INCSTAT(stats.numDListsCalled);
INCSTAT(stats.thisFrame.numDListsCalled);
// un-swap while((u32)(g_pVideoData - startAddress) < size)
Statistics::SwapDL(); {
Decode();
}
INCSTAT(stats.numDListsCalled);
INCSTAT(stats.thisFrame.numDListsCalled);
// reset to the old pointer // un-swap
g_pVideoData = old_pVideoData; Statistics::SwapDL();
// reset to the old pointer
g_pVideoData = old_pVideoData;
}
} }
bool FifoCommandRunnable() bool FifoCommandRunnable()

View File

@ -200,7 +200,7 @@ void TextureCache::Load(int stage, u32 address, int width, int height, int forma
{ // dump texture to file { // dump texture to file
static int counter = 0; static int counter = 0;
char szTemp[MAX_PATH]; char szTemp[MAX_PATH];
sprintf(szTemp, "%s\\txt_%04i_%i.png", g_Config.texDumpPath, counter++, format); sprintf(szTemp, "%s\\txt_%04i_%i.png", g_Config.texDumpPath.c_str(), counter++, format);
D3DXSaveTextureToFile(szTemp,D3DXIFF_BMP,entry.texture,0); D3DXSaveTextureToFile(szTemp,D3DXIFF_BMP,entry.texture,0);
} }

View File

@ -185,7 +185,7 @@ void CDebugger::CreateGUIControls()
// radio boxes ----------------------------------------------------- // radio boxes -----------------------------------------------------
int m_radioBoxNChoices[2]; int m_radioBoxNChoices[3];
wxString m_radioBoxChoices0[] = { wxT("Show base 10"), wxT("Show base 16") }; wxString m_radioBoxChoices0[] = { wxT("Show base 10"), wxT("Show base 16") };
m_radioBoxNChoices[0] = sizeof( m_radioBoxChoices0 ) / sizeof( wxString ); m_radioBoxNChoices[0] = sizeof( m_radioBoxChoices0 ) / sizeof( wxString );

View File

@ -84,10 +84,10 @@ class CDebugger : public wxDialog
private: private:
// declarations // declarations
wxCheckBox *m_Check[6]; wxCheckBox *m_Check[7];
wxRadioButton *m_Radio[5]; wxRadioButton *m_Radio[5];
wxRadioBox *m_RadioBox[3]; wxRadioBox *m_RadioBox[3];
wxStaticBox *m_Label[1]; wxStaticBox *m_Label[2];
wxPanel *m_Controller; wxPanel *m_Controller;
// WARNING: Make sure these are not also elsewhere, for example in resource.h. // WARNING: Make sure these are not also elsewhere, for example in resource.h.

View File

@ -51,20 +51,25 @@ static void ExecuteDisplayList(u32 address, u32 size)
u8* old_pVideoData = g_pVideoData; u8* old_pVideoData = g_pVideoData;
u8* startAddress = Memory_GetPtr(address); u8* startAddress = Memory_GetPtr(address);
g_pVideoData = startAddress;
// temporarily swap dl and non-dl (small "hack" for the stats) //Avoid the crash if Memory_GetPtr failed ..
Statistics::SwapDL(); if (startAddress!=0)
{
while ((u32)(g_pVideoData - startAddress) < size) g_pVideoData = startAddress;
{
Decode();
}
INCSTAT(stats.numDListsCalled);
INCSTAT(stats.thisFrame.numDListsCalled);
// un-swap // temporarily swap dl and non-dl (small "hack" for the stats)
Statistics::SwapDL(); Statistics::SwapDL();
while ((u32)(g_pVideoData - startAddress) < size)
{
Decode();
}
INCSTAT(stats.numDListsCalled);
INCSTAT(stats.thisFrame.numDListsCalled);
// un-swap
Statistics::SwapDL();
}
// reset to the old pointer // reset to the old pointer
g_pVideoData = old_pVideoData; g_pVideoData = old_pVideoData;