diff options
author | Vladislav Yaroslavlev <vladon@vladon.com> | 2015-10-12 16:56:14 +0300 |
---|---|---|
committer | Vladislav Yaroslavlev <vladon@vladon.com> | 2015-10-12 16:56:14 +0300 |
commit | 0daa6a72f316e0ec8c9ec7c85cc2a2b2a685b40c (patch) | |
tree | d5e116aa22cdae0b6549b3a773778993e3b264cd | |
parent | 6537e69498d400b299af7ac80e9c966ff867cd53 (diff) |
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
-rw-r--r-- | SimpleIni.h | 6 |
1 files 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<SI_CHAR,SI_STRLESS,SI_CONVERTER>::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<SI_CHAR,SI_STRLESS,SI_CONVERTER>::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<SI_CHAR,SI_STRLESS,SI_CONVERTER>::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; } |