Add check to prevent negative zero.

We want a canonical encoding for zero which is 0x4000000000000000 i.e. "positive
zero". So we want to disallow the alternative encoding 0x0000000000000000 i.e.
"negative zero".
This commit is contained in:
Stefan Thomas
2013-01-30 17:58:40 +01:00
parent bd71489032
commit 84dd5c2728

View File

@@ -570,12 +570,14 @@ STAmount* STAmount::construct(SerializerIterator& sit, SField::ref name)
{ // native
if ((value & cPosNative) != 0)
return new STAmount(name, value & ~cPosNative, false); // positive
else if (value == 0)
throw std::runtime_error("negative zero is not canonical");
return new STAmount(name, value, true); // negative
}
uint160 uCurrencyID = sit.get160();
if (!uCurrencyID)
throw std::runtime_error("invalid native currency");
throw std::runtime_error("invalid non-native currency");
uint160 uIssuerID = sit.get160();