Fix V668 PVS Studio - deal with pointer and NULL 272/head
authorsvost <ya.nowa@yandex.ru>
Fri, 12 Feb 2016 11:17:16 +0000 (14:17 +0300)
committersvost <ya.nowa@yandex.ru>
Fri, 12 Feb 2016 11:17:16 +0000 (14:17 +0300)
src/main.cpp
src/txdb-bdb.cpp
src/txdb-leveldb.cpp
src/util.cpp

index befcfaa..3291054 100644 (file)
@@ -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;
index bbfb656..5ce59b5 100644 (file)
@@ -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;
index 4a7a3cf..97bf88c 100644 (file)
@@ -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;
index f6d80f7..7fb43bc 100644 (file)
@@ -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();
     }