Fix division by zero errors in QueryTable
ClosedPublic

Authored by zivanfi on Dec 30 2018, 2:49 PM.

Details

Summary

Code used to try to divide by zero. Fixed it to always check for the
denominator being 0 beforehand.

BUG: 402708

Diff Detail

Repository
R261 KMyMoney
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
zivanfi requested review of this revision.Dec 30 2018, 2:49 PM
zivanfi created this revision.
ostroffjh added a subscriber: ostroffjh.

I think this should add the team as reviewer.

zivanfi updated this revision to Diff 48411.Dec 30 2018, 5:57 PM

Added unit test.

tbaumgart requested changes to this revision.Dec 30 2018, 6:43 PM
tbaumgart added a subscriber: tbaumgart.

I tested, that the testcase catches the problem and applied the patch which works as expected on the testcase. Good catch. Please see my minor resource usage improvements.

kmymoney/plugins/views/reports/core/querytable.cpp
363

Change

denominator == 0

to

denominator.isZero()

which is faster.

1062

Use

if (!(startingBal - buys).isZero()) {

here.

1461

Change

buysTotal.abs() == 0

to

buysTotal.isZero()

and save more CPU cycles. No need to take the absolute value of zero.

This revision now requires changes to proceed.Dec 30 2018, 6:43 PM
zivanfi updated this revision to Diff 48416.Dec 30 2018, 7:16 PM
zivanfi marked 3 inline comments as done.

Optimizations suggested by tbaumgart.

tbaumgart accepted this revision.Dec 30 2018, 7:20 PM
This revision is now accepted and ready to land.Dec 30 2018, 7:20 PM
aacid added a subscriber: aacid.Jan 16 2019, 11:03 PM

@tbaumgart the author doesn't have commit rights, want me to commit this?

@aacid Thanks for the notification. I'll take care of it.

This revision was automatically updated to reflect the committed changes.