From: <sag...@us...> - 2013-10-26 23:13:45
|
Revision: 3053 http://sourceforge.net/p/modplug/code/3053 Author: saga-games Date: 2013-10-26 23:13:38 +0000 (Sat, 26 Oct 2013) Log Message: ----------- [Ref] Use new with std::nothrow in more places instead of exception handling since it's actually slightly more readable and more in style with the surrounding code in those cases. Modified Paths: -------------- trunk/OpenMPT/mptrack/Autotune.cpp trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/soundlib/Dlsbank.cpp trunk/OpenMPT/soundlib/SampleFormats.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/load_j2b.cpp Modified: trunk/OpenMPT/mptrack/Autotune.cpp =================================================================== --- trunk/OpenMPT/mptrack/Autotune.cpp 2013-10-26 20:34:44 UTC (rev 3052) +++ trunk/OpenMPT/mptrack/Autotune.cpp 2013-10-26 23:13:38 UTC (rev 3053) @@ -109,11 +109,9 @@ { delete[] sampleData; } - try + sampleData = new (std::nothrow) int8[sampleLength]; + if(sampleData == nullptr) { - sampleData = new int8[sampleLength]; - } catch(MPTMemoryException) - { return false; } Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2013-10-26 20:34:44 UTC (rev 3052) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2013-10-26 23:13:38 UTC (rev 3053) @@ -309,12 +309,9 @@ if ((szPath[0]) && (!lstrcmpi(szPath, pszDllPath))) { - VSTPluginLib *p; - try + VSTPluginLib *p = new (std::nothrow) VSTPluginLib(pszDllPath); + if(p == nullptr) { - p = new VSTPluginLib(pszDllPath); - } catch(MPTMemoryException) - { return nullptr; } _splitpath(pszDllPath, nullptr, nullptr, p->szLibraryName, nullptr); @@ -368,12 +365,9 @@ HINSTANCE hLib; bool validPlug = false; - VSTPluginLib *p; - try + VSTPluginLib *p = new (std::nothrow) VSTPluginLib(pszDllPath); + if(p == nullptr) { - p = new VSTPluginLib(pszDllPath); - } catch(MPTMemoryException) - { return nullptr; } _splitpath(pszDllPath, nullptr, nullptr, p->szLibraryName, nullptr); Modified: trunk/OpenMPT/soundlib/Dlsbank.cpp =================================================================== --- trunk/OpenMPT/soundlib/Dlsbank.cpp 2013-10-26 20:34:44 UTC (rev 3052) +++ trunk/OpenMPT/soundlib/Dlsbank.cpp 2013-10-26 23:13:38 UTC (rev 3053) @@ -1701,11 +1701,9 @@ } #endif - try + pIns = new (std::nothrow) ModInstrument(); + if(pIns == nullptr) { - pIns = new ModInstrument(); - } catch(MPTMemoryException) - { return FALSE; } Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp =================================================================== --- trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-10-26 20:34:44 UTC (rev 3052) +++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-10-26 23:13:38 UTC (rev 3053) @@ -141,13 +141,9 @@ // Loading Instrument - ModInstrument *pIns; - - try + ModInstrument *pIns = new (std::nothrow) ModInstrument(nSample); + if(pIns == nullptr) { - pIns = new ModInstrument(nSample); - } catch(MPTMemoryException) - { return false; } @@ -254,13 +250,9 @@ } if (m_nInstruments < targetInstr) m_nInstruments = targetInstr; - ModInstrument *pIns; - - try + ModInstrument *pIns = new (std::nothrow) ModInstrument(); + if(pIns == nullptr) { - pIns = new ModInstrument(); - } catch(MPTMemoryException) - { return false; } @@ -720,7 +712,6 @@ GF1PATCHFILEHEADER *phdr = (GF1PATCHFILEHEADER *)lpStream; GF1INSTRUMENT *pih = (GF1INSTRUMENT *)(lpStream+sizeof(GF1PATCHFILEHEADER)); GF1LAYER *plh = (GF1LAYER *)(lpStream+sizeof(GF1PATCHFILEHEADER)+sizeof(GF1INSTRUMENT)); - ModInstrument *pIns; DWORD dwMemPos = sizeof(GF1PATCHFILEHEADER)+sizeof(GF1INSTRUMENT)+sizeof(GF1LAYER); UINT nSamples; @@ -731,11 +722,9 @@ || (!pih->layers) || (!plh->samples)) return false; if (nInstr > m_nInstruments) m_nInstruments = nInstr; - try + ModInstrument *pIns = new (std::nothrow) ModInstrument(); + if(pIns == nullptr) { - pIns = new ModInstrument(); - } catch(MPTMemoryException) - { return false; } @@ -874,13 +863,9 @@ return false; } - ModInstrument *pIns; - - try + ModInstrument *pIns = new (std::nothrow) ModInstrument(); + if(pIns == nullptr) { - pIns = new ModInstrument(); - } catch(MPTMemoryException) - { return false; } @@ -1496,13 +1481,9 @@ } if(nInstr > GetNumInstruments()) m_nInstruments = nInstr; - ModInstrument *pIns; - - try + ModInstrument *pIns = new (std::nothrow) ModInstrument(); + if(pIns == nullptr) { - pIns = new ModInstrument(); - } catch(MPTMemoryException) - { return false; } @@ -2170,12 +2151,9 @@ // Convert sample data to signed 32-Bit integer array. const SmpLength numSamples = sample.nLength * sample.GetNumChannels(); - FLAC__int32 *sampleData; - try + FLAC__int32 *sampleData = new (std::nothrow) FLAC__int32[numSamples]; + if(sampleData == nullptr) { - sampleData = new FLAC__int32[numSamples]; - } catch(MPTMemoryException) - { return false; } Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-10-26 20:34:44 UTC (rev 3052) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-10-26 23:13:38 UTC (rev 3053) @@ -974,15 +974,13 @@ // Allocate with some overhead (16 bytes before sample start, and at least 16 bytes after that) const size_t allocSize = (nbytes + 39) & ~7; - try + char *p = new (std::nothrow) char[allocSize]; + if(p != nullptr) { - char *p = new char[allocSize]; memset(p, 0, allocSize); return (p + 16); - } catch(MPTMemoryException) - { - return nullptr; } + return nullptr; } Modified: trunk/OpenMPT/soundlib/load_j2b.cpp =================================================================== --- trunk/OpenMPT/soundlib/load_j2b.cpp 2013-10-26 20:34:44 UTC (rev 3052) +++ trunk/OpenMPT/soundlib/load_j2b.cpp 2013-10-26 23:13:38 UTC (rev 3053) @@ -1015,13 +1015,10 @@ } // Header is valid, now unpack the RIFF AM file using inflate - Bytef *amFileData; uLongf destSize = fileHeader.unpackedLength; - try + Bytef *amFileData = new (std::nothrow) Bytef[destSize]; + if(amFileData == nullptr) { - amFileData = new Bytef[destSize]; - } catch(MPTMemoryException) - { return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |