X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fserialize.h;h=eacf51bc39fc3b720ce2fde65145808ff6e0f652;hb=98811f6ad4764f63e510d703d1659589c083fa05;hp=b169f75b2aae62344b9b1eebe4a6bf16a5e123f2;hpb=b90c9ecb132ad686275afafe506f8044719245ec;p=novacoin.git diff --git a/src/serialize.h b/src/serialize.h index b169f75..eacf51b 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -30,7 +30,7 @@ typedef unsigned long long uint64; #define for if (false) ; else for #endif -#ifdef __WXMSW__ +#ifdef WIN32 #include // This is used to attempt to keep keying material out of swap // Note that VirtualLock does not provide this as a guarantee on Windows, @@ -60,14 +60,17 @@ class CDataStream; class CAutoFile; static const unsigned int MAX_SIZE = 0x02000000; -static const int VERSION = 32500; +static const int VERSION = 50300; 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); +} ///////////////////////////////////////////////////////////////// // @@ -826,6 +829,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. @@ -835,7 +870,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;