From ad1ae6af23c29851ef8a1ed79f5111242406b001 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 10 Apr 2012 13:22:16 -0700 Subject: [PATCH] Fix mishandling of zero values. Must add to unit test! --- src/Amount.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Amount.cpp b/src/Amount.cpp index 4d2b60c4e..13169332d 100644 --- a/src/Amount.cpp +++ b/src/Amount.cpp @@ -33,7 +33,6 @@ STAmount* STAmount::construct(SerializerIterator& sit, const char *name) { uint64 value = sit.get64(); int offset = static_cast(value>>(64-8)); - offset-=142; value&=~(255ull<<(64-8)); if(value==0) { @@ -42,6 +41,7 @@ STAmount* STAmount::construct(SerializerIterator& sit, const char *name) } else { + offset-=142; if( (valuecMaxValue) || (offsetcMaxOffset) ) throw std::runtime_error("invalid currency value"); } @@ -58,7 +58,7 @@ std::string STAmount::getText() const void STAmount::add(Serializer& s) const { uint64 v=value; - v+=(static_cast(offset+142) << (64-8)); + if(v!=0) v+=(static_cast(offset+142) << (64-8)); s.add64(v); }