changeset 2820:58f6e1c24cd1 draft

Code cleanup: use ECDSA_size() instead of fixed 10,000 byte sig buffer, and explicity init static var
author Gavin Andresen <gavinandresen@gmail.com>
date Mon, 19 Dec 2011 19:04:47 -0500
parents 2e68e01c90ad
children b38471ef2118
files src/key.h src/main.cpp
diffstat 2 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/key.h
+++ b/src/key.h
@@ -214,13 +214,14 @@
 
     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;
     }
 
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1921,7 +1921,7 @@
         }
 
         // 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))