diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-03-05 09:35:13 +0100 |
---|---|---|
committer | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-03-05 09:35:13 +0100 |
commit | 7446e8cddddcf02b704bdc1a8bfe74609acbb0d9 (patch) | |
tree | d2a6bc591ff4f2e6e13b5aab25ed77c19f5867c3 | |
parent | 3fcac9022cca520209352c498320809bfb66e2c9 (diff) | |
download | subsurface-7446e8cddddcf02b704bdc1a8bfe74609acbb0d9.tar.gz |
statistics: don't divide by totalCount = 0 in pie charts
This silences a Coverity warning. In principle, this should
never happen, since there are no slices if totalCount is 0.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | stats/pieseries.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/stats/pieseries.cpp b/stats/pieseries.cpp index c425fffd2..84f80b01d 100644 --- a/stats/pieseries.cpp +++ b/stats/pieseries.cpp @@ -27,6 +27,11 @@ PieSeries::Item::Item(StatsView &view, const QString &name, int from, std::vecto QLocale loc; int count = (int)dives.size(); + + // totalCount = 0 shouldn't happen, but for robustness' sake, let's not divide by zero. + if (totalCount <= 0) + totalCount = count = 1; + angleFrom = static_cast<double>(from) / totalCount; angleTo = static_cast<double>(from + count) / totalCount; double meanAngle = M_PI / 2.0 - (from + count / 2.0) / totalCount * M_PI * 2.0; // Note: "-" because we go CW. |