Check whether this_bal actually finds a matching commodity value, otherwise
it's a divide by zero.
This commit is contained in:
parent
95f323f137
commit
a2e16273f6
1 changed files with 19 additions and 17 deletions
36
journal.cc
36
journal.cc
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue