From ddc8fcf66fd04dd3685a7788d62c2a00ce2a27ee Mon Sep 17 00:00:00 2001 From: Kunht Kun Date: Sat, 12 Mar 2022 00:04:10 -0500 Subject: 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 --- src/amount.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/amount.cc') 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)); -- cgit v1.2.3