From: Gavin Andresen Date: Tue, 20 Dec 2011 00:04:47 +0000 (-0500) Subject: Code cleanup: use ECDSA_size() instead of fixed 10,000 byte sig buffer, and explicity... X-Git-Tag: v0.4.0-unstable~129^2~1^2^2~2^2^2~52 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=4986c35d74afd6fc313d7637eb0220f3df500009 Code cleanup: use ECDSA_size() instead of fixed 10,000 byte sig buffer, and explicity init static var --- diff --git a/src/key.h b/src/key.h index 89d82fc..477f550 100644 --- a/src/key.h +++ b/src/key.h @@ -214,13 +214,14 @@ public: bool Sign(uint256 hash, std::vector& 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; } diff --git a/src/main.cpp b/src/main.cpp index 652d4c1..cd02652 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1921,7 +1921,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))