summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKunht Kun <kunhtkun@gmail.com>2022-03-12 00:04:10 -0500
committerMartin Michlmayr <tbm@cyrius.com>2022-03-12 17:11:55 +0800
commitddc8fcf66fd04dd3685a7788d62c2a00ce2a27ee (patch)
tree7c7ec18e1f0bf59bb4faf87151d259c87ed4b12d /src
parentba8ec32435313b4749a3733071b3184ca6bd8e14 (diff)
downloadfork-ledger-ddc8fcf66fd04dd3685a7788d62c2a00ce2a27ee.tar.gz
fork-ledger-ddc8fcf66fd04dd3685a7788d62c2a00ce2a27ee.tar.bz2
fork-ledger-ddc8fcf66fd04dd3685a7788d62c2a00ce2a27ee.zip
Avoid dereferencing null pointer
Here `comm` could be a null pointer (the new test regress/2057 shows such a case). So test it before dereferencing to avoid segfault. Re: #2057
Diffstat (limited to 'src')
-rw-r--r--src/amount.cc3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/amount.cc b/src/amount.cc
index 0527c979..079ce777 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -732,7 +732,8 @@ void amount_t::in_place_unreduce()
}
if (shifted) {
- if (("h" == comm->symbol() || "m" == comm->symbol()) && commodity_t::time_colon_by_default) {
+ if (comm && ("h" == comm->symbol() || "m" == comm->symbol())
+ && commodity_t::time_colon_by_default) {
double truncated = trunc(tmp.to_double());
double precision = tmp.to_double() - truncated;
tmp = truncated + (precision * (comm->smaller()->number() / 100.0));