From 627162acc0393aa8e9f4aaf45b52adab518aac4a Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 19 Jun 2010 13:34:15 -0400 Subject: [PATCH] Made amount_t::value a bit safer --- src/amount.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/amount.cc b/src/amount.cc index 9817f464..a5c54ce6 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -743,21 +743,22 @@ amount_t::value(const optional& moment, optional point; optional comm(in_terms_of); - if (comm && commodity().referent() == comm->referent()) { - return *this; - } - else if (has_annotation() && annotation().price) { + if (has_annotation() && annotation().price) { if (annotation().has_flags(ANNOTATION_PRICE_FIXATED)) { point = price_point_t(); point->price = *annotation().price; } - else if (! in_terms_of) { + else if (! comm) { comm = annotation().price->commodity(); } } if (! point) { + if (comm && commodity().referent() == comm->referent()) + return *this; + point = commodity().find_price(comm, moment); + // Whether a price was found or not, check whether we should attempt // to download a price from the Internet. This is done if (a) no // price was found, or (b) the price is "stale" according to the