Skip to content

Commit

Permalink
Code cleanup: use ECDSA_size() instead of fixed 10,000 byte sig buffe…
Browse files Browse the repository at this point in the history
…r, and explicity init static var
  • Loading branch information
gavinandresen committed Dec 20, 2011
1 parent 26ce92b commit 9ef7fa3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,14 @@ class CKey

bool Sign(uint256 hash, std::vector<unsigned char>& vchSig)
{
vchSig.clear();
unsigned char pchSig[10000];
unsigned int nSize = 0;
if (!ECDSA_sign(0, (unsigned char*)&hash, sizeof(hash), pchSig, &nSize, pkey))
unsigned int nSize = ECDSA_size(pkey);
vchSig.resize(nSize); // Make sure it is big enough
if (!ECDSA_sign(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], &nSize, pkey))
{
vchSig.clear();
return false;
vchSig.resize(nSize);
memcpy(&vchSig[0], pchSig, nSize);
}
vchSig.resize(nSize); // Shrink to fit actual size
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
}

// Ask the first connected node for block updates
static int nAskedForBlocks;
static int nAskedForBlocks = 0;
if (!pfrom->fClient &&
(pfrom->nVersion < 32000 || pfrom->nVersion >= 32400) &&
(nAskedForBlocks < 1 || vNodes.size() <= 1))
Expand Down

0 comments on commit 9ef7fa3

Please sign in to comment.