From 98df8290193fa757ef4be420e2dd08e50c0bab07 Mon Sep 17 00:00:00 2001 From: ip_gpu Date: Wed, 1 Nov 2017 14:31:01 +0500 Subject: [PATCH] fixed from PVS-Studio V668 There is no sense in testing the pointer against null, as the memory was allocated using the 'new' operator. The exception will be generated in the case of memory allocation error. load_mt2.cpp --- third_party/libmodplug/src/load_mt2.cpp | 24 +++++++++++++----------- third_party/libmodplug/src/sndfile.h | 2 ++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/third_party/libmodplug/src/load_mt2.cpp b/third_party/libmodplug/src/load_mt2.cpp index bf8bb25..cbc5b74 100644 --- a/third_party/libmodplug/src/load_mt2.cpp +++ b/third_party/libmodplug/src/load_mt2.cpp @@ -251,11 +251,12 @@ BOOL CSoundFile::ReadMT2(LPCBYTE lpStream, DWORD dwMemLength) { DWORD nTxtLen = dwLen; if (nTxtLen > 32000) nTxtLen = 32000; - m_lpszSongComments = new char[nTxtLen]; // changed from CHAR - if (m_lpszSongComments) - { - memcpy(m_lpszSongComments, lpStream+dwMemPos+1, nTxtLen-1); - m_lpszSongComments[nTxtLen-1] = 0; + try { + m_lpszSongComments = new char[nTxtLen]; // changed from CHAR + memcpy(m_lpszSongComments, lpStream + dwMemPos + 1, nTxtLen - 1); + m_lpszSongComments[nTxtLen - 1] = 0; + } + catch (std::bad_alloc& ba) { } } break; @@ -402,19 +403,20 @@ BOOL CSoundFile::ReadMT2(LPCBYTE lpStream, DWORD dwMemLength) INSTRUMENTHEADER *penv = NULL; if (iIns <= m_nInstruments) { - penv = new INSTRUMENTHEADER; - Headers[iIns] = penv; - if (penv) - { + try { + penv = new INSTRUMENTHEADER; + Headers[iIns] = penv; memset(penv, 0, sizeof(INSTRUMENTHEADER)); memcpy(penv->name, pmi->szName, 32); penv->nGlobalVol = 64; penv->nPan = 128; - for (UINT i=0; iNoteMap[i] = i+1; + penv->NoteMap[i] = i + 1; } } + catch (std::bad_alloc& ba) { + } } #ifdef MT2DEBUG if (iIns <= pfh->wInstruments) Log(" Instrument #%d at offset %04X: %d bytes\n", iIns, dwMemPos, pmi->dwDataLen); diff --git a/third_party/libmodplug/src/sndfile.h b/third_party/libmodplug/src/sndfile.h index c009265..84592ca 100644 --- a/third_party/libmodplug/src/sndfile.h +++ b/third_party/libmodplug/src/sndfile.h @@ -13,6 +13,8 @@ #ifndef __SNDFILE_H #define __SNDFILE_H +#include + #ifdef UNDER_CE int _strnicmp(const char *str1,const char *str2, int n); #endif