From 31e9cb26642187e571f178ddcfa268ce7c4e56cc Mon Sep 17 00:00:00 2001 From: svost Date: Fri, 12 Feb 2016 14:17:16 +0300 Subject: [PATCH] Fix V668 PVS Studio - deal with pointer and NULL --- src/main.cpp | 2 +- src/txdb-bdb.cpp | 2 +- src/txdb-leveldb.cpp | 2 +- src/util.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index befcfaa..3291054 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2137,7 +2137,7 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos) return error("AddToBlockIndex() : %s already exists", hash.ToString().substr(0,20).c_str()); // Construct new block index object - CBlockIndex* pindexNew = new CBlockIndex(nFile, nBlockPos, *this); + CBlockIndex* pindexNew = new(nothrow) CBlockIndex(nFile, nBlockPos, *this); if (!pindexNew) return error("AddToBlockIndex() : new CBlockIndex failed"); pindexNew->phashBlock = &hash; diff --git a/src/txdb-bdb.cpp b/src/txdb-bdb.cpp index bbfb656..5ce59b5 100644 --- a/src/txdb-bdb.cpp +++ b/src/txdb-bdb.cpp @@ -160,7 +160,7 @@ CBlockIndex static * InsertBlockIndex(uint256 hash) return (*mi).second; // Create new - CBlockIndex* pindexNew = new CBlockIndex(); + CBlockIndex* pindexNew = new(nothrow) CBlockIndex(); if (!pindexNew) throw runtime_error("LoadBlockIndex() : new CBlockIndex failed"); mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first; diff --git a/src/txdb-leveldb.cpp b/src/txdb-leveldb.cpp index 4a7a3cf..97bf88c 100644 --- a/src/txdb-leveldb.cpp +++ b/src/txdb-leveldb.cpp @@ -325,7 +325,7 @@ static CBlockIndex *InsertBlockIndex(uint256 hash) return (*mi).second; // Create new - CBlockIndex* pindexNew = new CBlockIndex(); + CBlockIndex* pindexNew = new(nothrow) CBlockIndex(); if (!pindexNew) throw runtime_error("LoadBlockIndex() : new CBlockIndex failed"); mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first; diff --git a/src/util.cpp b/src/util.cpp index f6d80f7..7fb43bc 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -331,7 +331,7 @@ string vstrprintf(const char *format, va_list ap) if (p != buffer) delete[] p; limit *= 2; - p = new char[limit]; + p = new(nothrow) char[limit]; if (p == NULL) throw std::bad_alloc(); } -- 1.7.1