From 0daa6a72f316e0ec8c9ec7c85cc2a2b2a685b40c Mon Sep 17 00:00:00 2001 From: Vladislav Yaroslavlev Date: Mon, 12 Oct 2015 16:56:14 +0300 Subject: correct use of `new` `new` without `std::nothrow` does not return NULL, it throws an exception; use `new(std::nothrow)` instead for correct detecting of no memory error --- SimpleIni.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SimpleIni.h b/SimpleIni.h index 5fcd2ee..aee5bee 100644 --- a/SimpleIni.h +++ b/SimpleIni.h @@ -1387,7 +1387,7 @@ CSimpleIniTempl::LoadFile( } // allocate and ensure NULL terminated - char * pData = new char[lSize+1]; + char * pData = new(std::nothrow) char[lSize+1]; if (!pData) { return SI_NOMEM; } @@ -1436,7 +1436,7 @@ CSimpleIniTempl::LoadData( // allocate memory for the data, ensure that there is a NULL // terminator wherever the converted data ends - SI_CHAR * pData = new SI_CHAR[uLen+1]; + SI_CHAR * pData = new(std::nothrow) SI_CHAR[uLen+1]; if (!pData) { return SI_NOMEM; } @@ -1861,7 +1861,7 @@ CSimpleIniTempl::CopyString( for ( ; a_pString[uLen]; ++uLen) /*loop*/ ; } ++uLen; // NULL character - SI_CHAR * pCopy = new SI_CHAR[uLen]; + SI_CHAR * pCopy = new(std::nothrow) SI_CHAR[uLen]; if (!pCopy) { return SI_NOMEM; } -- cgit v1.2.3