From 818d2d04e826c35f2f1ca97c954078694ac1561e Mon Sep 17 00:00:00 2001 From: ip_gpu Date: Wed, 1 Nov 2017 14:44:40 +0500 Subject: [PATCH] fixed from PVS-Studio V668 There is no sense in testing the 'm_lpszSongComments' 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_ult.cpp 68 --- third_party/libmodplug/src/load_ult.cpp | 13 +++++++------ third_party/libmodplug/src/sndfile.h | 2 ++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/third_party/libmodplug/src/load_ult.cpp b/third_party/libmodplug/src/load_ult.cpp index 83024f2..65f4a14 100644 --- a/third_party/libmodplug/src/load_ult.cpp +++ b/third_party/libmodplug/src/load_ult.cpp @@ -64,16 +64,17 @@ BOOL CSoundFile::ReadUlt(const BYTE *lpStream, DWORD dwMemLength) if ((pmh->reserved) && (dwMemPos + pmh->reserved * 32 < dwMemLength)) { UINT len = pmh->reserved * 32; - m_lpszSongComments = new char[len + 1 + pmh->reserved]; - if (m_lpszSongComments) - { - for (UINT l=0; lreserved; l++) + try { + m_lpszSongComments = new char[len + 1 + pmh->reserved]; + for (UINT l = 0; l < pmh->reserved; l++) { - memcpy(m_lpszSongComments+l*33, lpStream+dwMemPos+l*32, 32); - m_lpszSongComments[l*33+32] = 0x0D; + memcpy(m_lpszSongComments + l * 33, lpStream + dwMemPos + l * 32, 32); + m_lpszSongComments[l * 33 + 32] = 0x0D; } m_lpszSongComments[len] = 0; } + catch (std::bad_alloc& ba) { + } dwMemPos += len; } if (dwMemPos >= dwMemLength) return TRUE; 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