summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-07-17 17:37:03 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-07-17 17:37:03 -0400
commita2e16273f6f437d39b71ec53861c859b8f9b9e92 (patch)
treedec7e066e4ddea2299cbdd0e6d5f4a39696026bc
parent95f323f1378414080149b6ce535bb0f1918c7b35 (diff)
downloadfork-ledger-a2e16273f6f437d39b71ec53861c859b8f9b9e92.tar.gz
fork-ledger-a2e16273f6f437d39b71ec53861c859b8f9b9e92.tar.bz2
fork-ledger-a2e16273f6f437d39b71ec53861c859b8f9b9e92.zip
Check whether this_bal actually finds a matching commodity value, otherwise
it's a divide by zero.
-rw-r--r--journal.cc36
1 files changed, 19 insertions, 17 deletions
diff --git a/journal.cc b/journal.cc
index 4916cd6f..4b3da90c 100644
--- a/journal.cc
+++ b/journal.cc
@@ -161,28 +161,30 @@ bool entry_base_t::finalize()
if (this_bal == other_bal)
other_bal++;
- amount_t per_unit_cost =
- amount_t((*other_bal).second / (*this_bal).second).unround();
+ if (this_bal != ((balance_t *) balance.data)->amounts.end()) {
+ amount_t per_unit_cost =
+ amount_t((*other_bal).second / (*this_bal).second).unround();
- for (; x != transactions.end(); x++) {
- if ((*x)->cost || ((*x)->flags & TRANSACTION_VIRTUAL) ||
- ! (*x)->amount || (*x)->amount.commodity() != this_comm)
- continue;
+ for (; x != transactions.end(); x++) {
+ if ((*x)->cost || ((*x)->flags & TRANSACTION_VIRTUAL) ||
+ ! (*x)->amount || (*x)->amount.commodity() != this_comm)
+ continue;
- assert((*x)->amount);
- balance -= (*x)->amount;
+ assert((*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() &&
- ! (*x)->amount.commodity().annotated)
- (*x)->amount.annotate_commodity
- (abs(per_unit_cost),
- entry ? entry->actual_date() : datetime_t(),
- entry ? entry->code : "");
+ if ((*x)->amount.commodity() &&
+ ! (*x)->amount.commodity().annotated)
+ (*x)->amount.annotate_commodity
+ (abs(per_unit_cost),
+ entry ? entry->actual_date() : datetime_t(),
+ entry ? entry->code : "");
- (*x)->cost = new amount_t(- (per_unit_cost * (*x)->amount));
- balance += *(*x)->cost;
+ (*x)->cost = new amount_t(- (per_unit_cost * (*x)->amount));
+ balance += *(*x)->cost;
+ }
}
}