X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fserialize.h;h=d7b5ec80d564acc0cf5b4e4c0524f1273cbb1a41;hb=6e1e62a04c79a93d124371fa102d7881449b3673;hp=c55775242b083c1773150f9ab824246b875a2d44;hpb=498a2c9b162dd5e7281e80e364eb82f3e2b333cb;p=novacoin.git diff --git a/src/serialize.h b/src/serialize.h index c557752..d7b5ec8 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -59,14 +59,17 @@ class CDataStream; class CAutoFile; static const unsigned int MAX_SIZE = 0x02000000; -static const int VERSION = 32500; +static const int VERSION = 40400; static const char* pszSubVer = ""; static const bool VERSION_IS_BETA = true; - - - - +// Used to bypass the rule against non-const reference to temporary +// where it makes sense with wrappers such as CFlatData or CTxDB +template +inline T& REF(const T& val) +{ + return const_cast(val); +} ///////////////////////////////////////////////////////////////// // @@ -825,6 +828,38 @@ struct secure_allocator : public std::allocator }; +// +// Allocator that clears its contents before deletion. +// +template +struct zero_after_free_allocator : public std::allocator +{ + // MSVC8 default copy constructor is broken + typedef std::allocator base; + typedef typename base::size_type size_type; + typedef typename base::difference_type difference_type; + typedef typename base::pointer pointer; + typedef typename base::const_pointer const_pointer; + typedef typename base::reference reference; + typedef typename base::const_reference const_reference; + typedef typename base::value_type value_type; + zero_after_free_allocator() throw() {} + zero_after_free_allocator(const zero_after_free_allocator& a) throw() : base(a) {} + template + zero_after_free_allocator(const zero_after_free_allocator& a) throw() : base(a) {} + ~zero_after_free_allocator() throw() {} + template struct rebind + { typedef zero_after_free_allocator<_Other> other; }; + + void deallocate(T* p, std::size_t n) + { + if (p != NULL) + memset(p, 0, sizeof(T) * n); + std::allocator::deallocate(p, n); + } +}; + + // // Double ended buffer combining vector and stream-like interfaces. @@ -834,7 +869,7 @@ struct secure_allocator : public std::allocator class CDataStream { protected: - typedef std::vector > vector_type; + typedef std::vector > vector_type; vector_type vch; unsigned int nReadPos; short state;