From: <sag...@us...> - 2011-09-18 19:38:20
|
Revision: 1039 http://modplug.svn.sourceforge.net/modplug/?rev=1039&view=rev Author: saga-games Date: 2011-09-18 19:38:13 +0000 (Sun, 18 Sep 2011) Log Message: ----------- [Ref] Changed catch(...) to catch(MPTMemoryException) when catching "operator new" exceptions. (Using a custom typedef is a quick workaround for MFC apps not making use of std::bad_alloc by default) Modified Paths: -------------- trunk/OpenMPT/mptrack/Modedit.cpp trunk/OpenMPT/mptrack/Stdafx.h trunk/OpenMPT/mptrack/test/test.cpp trunk/OpenMPT/soundlib/Dlsbank.cpp trunk/OpenMPT/soundlib/Load_imf.cpp trunk/OpenMPT/soundlib/Load_mid.cpp trunk/OpenMPT/soundlib/Message.cpp trunk/OpenMPT/soundlib/pattern.cpp Modified: trunk/OpenMPT/mptrack/Modedit.cpp =================================================================== --- trunk/OpenMPT/mptrack/Modedit.cpp 2011-09-17 22:41:42 UTC (rev 1038) +++ trunk/OpenMPT/mptrack/Modedit.cpp 2011-09-18 19:38:13 UTC (rev 1039) @@ -501,14 +501,14 @@ try { MODINSTRUMENT *p = new MODINSTRUMENT(smp); - InitializeInstrument(p); m_SndFile.Instruments[smp] = p; - lstrcpyn(p->name, m_SndFile.m_szNames[smp], CountOf(p->name)); - } catch(...) + } catch(MPTMemoryException) { ErrorBox(IDS_ERR_OUTOFMEMORY, CMainFrame::GetMainFrame()); return INSTRUMENTINDEX_INVALID; } + InitializeInstrument(m_SndFile.Instruments[smp]); + lstrcpyn(m_SndFile.Instruments[smp]->name, m_SndFile.m_szNames[smp], MAX_INSTRUMENTNAME); } } m_SndFile.m_nInstruments = nInstruments; @@ -562,12 +562,12 @@ try { pIns = new MODINSTRUMENT(newsmp); - InitializeInstrument(pIns); - } catch(...) + } catch(MPTMemoryException) { ErrorBox(IDS_ERR_OUTOFMEMORY, CMainFrame::GetMainFrame()); return INSTRUMENTINDEX_INVALID; } + InitializeInstrument(pIns); CriticalSection cs; Modified: trunk/OpenMPT/mptrack/Stdafx.h =================================================================== --- trunk/OpenMPT/mptrack/Stdafx.h 2011-09-17 22:41:42 UTC (rev 1038) +++ trunk/OpenMPT/mptrack/Stdafx.h 2011-09-18 19:38:13 UTC (rev 1039) @@ -96,6 +96,9 @@ #include "../common/typedefs.h" +// Exception type that is used to catch "operator new" exceptions. +typedef CMemoryException * MPTMemoryException; + //To mark string that should be translated in case of multilingual version. #define GetStrI18N(x) (x) Modified: trunk/OpenMPT/mptrack/test/test.cpp =================================================================== --- trunk/OpenMPT/mptrack/test/test.cpp 2011-09-17 22:41:42 UTC (rev 1038) +++ trunk/OpenMPT/mptrack/test/test.cpp 2011-09-18 19:38:13 UTC (rev 1039) @@ -126,11 +126,11 @@ if (!dwVerInfoSize) throw std::runtime_error("!dwVerInfoSize is true"); - char* pVersionInfo; + char *pVersionInfo; try { pVersionInfo = new char[dwVerInfoSize]; - } catch(...) + } catch(MPTMemoryException) { throw std::runtime_error("Could not allocate memory for pVersionInfo"); } Modified: trunk/OpenMPT/soundlib/Dlsbank.cpp =================================================================== --- trunk/OpenMPT/soundlib/Dlsbank.cpp 2011-09-17 22:41:42 UTC (rev 1038) +++ trunk/OpenMPT/soundlib/Dlsbank.cpp 2011-09-18 19:38:13 UTC (rev 1039) @@ -1646,7 +1646,7 @@ try { pIns = new MODINSTRUMENT(); - } catch(...) + } catch(MPTMemoryException) { return FALSE; } Modified: trunk/OpenMPT/soundlib/Load_imf.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_imf.cpp 2011-09-17 22:41:42 UTC (rev 1038) +++ trunk/OpenMPT/soundlib/Load_imf.cpp 2011-09-18 19:38:13 UTC (rev 1039) @@ -499,8 +499,7 @@ try { pIns = new MODINSTRUMENT(); - } - catch(...) + } catch(MPTMemoryException) { continue; } Modified: trunk/OpenMPT/soundlib/Load_mid.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mid.cpp 2011-09-17 22:41:42 UTC (rev 1038) +++ trunk/OpenMPT/soundlib/Load_mid.cpp 2011-09-18 19:38:13 UTC (rev 1039) @@ -416,7 +416,7 @@ try { pIns = new MODINSTRUMENT(); - } catch(...) + } catch(MPTMemoryException) { return 0; } Modified: trunk/OpenMPT/soundlib/Message.cpp =================================================================== --- trunk/OpenMPT/soundlib/Message.cpp 2011-09-17 22:41:42 UTC (rev 1038) +++ trunk/OpenMPT/soundlib/Message.cpp 2011-09-18 19:38:13 UTC (rev 1039) @@ -28,7 +28,7 @@ m_lpszSongComments = new char[length + 1]; // + 1 for trailing null memset(m_lpszSongComments, 0, length + 1); return true; - } catch(...) + } catch(MPTMemoryException) { m_lpszSongComments = nullptr; return false; Modified: trunk/OpenMPT/soundlib/pattern.cpp =================================================================== --- trunk/OpenMPT/soundlib/pattern.cpp 2011-09-17 22:41:42 UTC (rev 1038) +++ trunk/OpenMPT/soundlib/pattern.cpp 2011-09-18 19:38:13 UTC (rev 1039) @@ -253,10 +253,10 @@ { try { - MODCOMMAND *p = new MODCOMMAND[rows*nchns]; + MODCOMMAND *p = new MODCOMMAND[rows * nchns]; memset(p, 0, rows * nchns * sizeof(MODCOMMAND)); return p; - } catch (...) + } catch(MPTMemoryException) { return nullptr; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |