From 9ef7fa344741cb34ba4e15cff06d61d1c7a74e24 Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Mon, 19 Dec 2011 19:04:47 -0500 Subject: Code cleanup: use ECDSA_size() instead of fixed 10,000 byte sig buffer, and explicity init static var --- src/key.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/key.h') diff --git a/src/key.h b/src/key.h index 3f4b72d2d3..94ec55228e 100644 --- a/src/key.h +++ b/src/key.h @@ -178,13 +178,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; } -- cgit v1.2.3