Check whether this_bal actually finds a matching commodity value, otherwise

it's a divide by zero.
This commit is contained in:
John Wiegley 2008-07-17 17:37:03 -04:00
parent 95f323f137
commit a2e16273f6

View file

@ -161,28 +161,30 @@ bool entry_base_t::finalize()
if (this_bal == other_bal) if (this_bal == other_bal)
other_bal++; other_bal++;
amount_t per_unit_cost = if (this_bal != ((balance_t *) balance.data)->amounts.end()) {
amount_t((*other_bal).second / (*this_bal).second).unround(); amount_t per_unit_cost =
amount_t((*other_bal).second / (*this_bal).second).unround();
for (; x != transactions.end(); x++) { for (; x != transactions.end(); x++) {
if ((*x)->cost || ((*x)->flags & TRANSACTION_VIRTUAL) || if ((*x)->cost || ((*x)->flags & TRANSACTION_VIRTUAL) ||
! (*x)->amount || (*x)->amount.commodity() != this_comm) ! (*x)->amount || (*x)->amount.commodity() != this_comm)
continue; continue;
assert((*x)->amount); assert((*x)->amount);
balance -= (*x)->amount; balance -= (*x)->amount;
entry_t * entry = dynamic_cast<entry_t *>(this); entry_t * entry = dynamic_cast<entry_t *>(this);
if ((*x)->amount.commodity() && if ((*x)->amount.commodity() &&
! (*x)->amount.commodity().annotated) ! (*x)->amount.commodity().annotated)
(*x)->amount.annotate_commodity (*x)->amount.annotate_commodity
(abs(per_unit_cost), (abs(per_unit_cost),
entry ? entry->actual_date() : datetime_t(), entry ? entry->actual_date() : datetime_t(),
entry ? entry->code : ""); entry ? entry->code : "");
(*x)->cost = new amount_t(- (per_unit_cost * (*x)->amount)); (*x)->cost = new amount_t(- (per_unit_cost * (*x)->amount));
balance += *(*x)->cost; balance += *(*x)->cost;
}
} }
} }