From 91eab2b5d2d792ca59088ad4850ed3bfed566070 Mon Sep 17 00:00:00 2001 From: ip_gpu Date: Wed, 1 Nov 2017 14:51:00 +0500 Subject: [PATCH] fixed from PVS-Studio V668 There is no sense in testing the 'p' pointer against null, as the memory was allocated using the 'new' operator. The exception will be generated in the case of memory allocation error. sndfile.cpp --- third_party/libmodplug/src/sndfile.cpp | 20 ++++++++++++++++---- third_party/libmodplug/src/sndfile.h | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/third_party/libmodplug/src/sndfile.cpp b/third_party/libmodplug/src/sndfile.cpp index 7e4096f..0deede9 100644 --- a/third_party/libmodplug/src/sndfile.cpp +++ b/third_party/libmodplug/src/sndfile.cpp @@ -339,8 +339,13 @@ BOOL CSoundFile::Destroy() MODCOMMAND *CSoundFile::AllocatePattern(UINT rows, UINT nchns) //------------------------------------------------------------ { - MODCOMMAND *p = new MODCOMMAND[rows*nchns]; - if (p) memset(p, 0, rows*nchns*sizeof(MODCOMMAND)); + try { + MODCOMMAND *p = new MODCOMMAND[rows*nchns]; + memset(p, 0, rows*nchns*sizeof(MODCOMMAND)); + } + catch (std::bad_alloc& ba) { + } + return p; } @@ -1777,8 +1782,15 @@ BOOL CSoundFile::SetPatternName(UINT nPat, LPCSTR lpszName) { if (!lpszName[0]) return TRUE; UINT len = (nPat+1)*MAX_PATTERNNAME; - char *p = new char[len]; - if (!p) return FALSE; + + char *p; + try { + p = new char[len]; + } + catch (std::bad_alloc& ba) { + return FALSE; + } + memset(p, 0, len); if (m_lpszPatternNames) { 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