Merge pull request #274 from svost/patch
author0xDEADFACE <masmfan@gmail.com>
Sat, 13 Feb 2016 22:53:43 +0000 (01:53 +0300)
committer0xDEADFACE <masmfan@gmail.com>
Sat, 13 Feb 2016 22:53:43 +0000 (01:53 +0300)
Fix V595 PVS Studio - the pointer was utilized before it was verified…

1  2 
src/ecies.cpp
src/main.cpp

diff --combined src/ecies.cpp
@@@ -11,6 -11,7 +11,6 @@@
  #include "ies.h"
  #include <iostream>
  #include <vector>
 -#include <openssl/ecdh.h>
  
  #define SET_ERROR(string) \
      sprintf(error, "%s %s:%d", (string), __FILE__, __LINE__)
@@@ -272,16 -273,16 +272,16 @@@ static int store_mac_tag(const ies_ctx_
  
  cryptogram_t * ecies_encrypt(const ies_ctx_t *ctx, const unsigned char *data, size_t length, char *error) {
  
-     const size_t block_length = EVP_CIPHER_block_size(ctx->cipher);
-     const size_t mac_length = EVP_MD_size(ctx->md);
-     cryptogram_t *cryptogram = NULL;
-     unsigned char *envelope_key = NULL;
      if (!ctx || !data || !length) {
          SET_ERROR("Invalid arguments");
          return NULL;
      }
  
+     const size_t block_length = EVP_CIPHER_block_size(ctx->cipher);
+     const size_t mac_length = EVP_MD_size(ctx->md);
+     cryptogram_t *cryptogram = NULL;
+     unsigned char *envelope_key = NULL;
      if (block_length == 0 || block_length > EVP_MAX_BLOCK_LENGTH) {
          SET_ERROR("Derived block size is incorrect");
          return NULL;
diff --combined src/main.cpp
@@@ -1189,11 -1189,11 +1189,11 @@@ const CBlockIndex* GetLastBlockIndex(co
  
  unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake)
  {
      if (pindexLast == NULL)
          return bnTargetLimit.GetCompact(); // genesis block
  
+     CBigNum bnTargetLimit = !fProofOfStake ? bnProofOfWorkLimit : GetProofOfStakeLimit(pindexLast->nHeight, pindexLast->nTime);
      const CBlockIndex* pindexPrev = GetLastBlockIndex(pindexLast, fProofOfStake);
      if (pindexPrev->pprev == NULL)
          return bnTargetLimit.GetCompact(); // first block
@@@ -2137,7 -2137,7 +2137,7 @@@ bool CBlock::AddToBlockIndex(unsigned i
          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;