Never divide by zero.
authorMilian Wolff <mail@milianw.de>
Thu, 24 Mar 2016 19:33:10 +0000 (20:33 +0100)
committerMilian Wolff <mail@milianw.de>
Thu, 24 Mar 2016 19:33:10 +0000 (20:33 +0100)
gui/callercalleemodel.cpp

index 3dc8f60..c909620 100644 (file)
@@ -23,6 +23,8 @@
 
 #include <QTextStream>
 
+#include <cmath>
+
 namespace{
 /// TODO: share code
 QString basename(const QString& path)
@@ -227,12 +229,12 @@ QVariant CallerCalleeModel::data(const QModelIndex& index, int role) const
         stream << '\n';
         stream << i18n("inclusive: allocated %1 over %2 calls (%3 temporary, i.e. %4%), peak at %5, leaked %6",
                        m_format.formatByteSize(row.inclusiveCost.allocated), row.inclusiveCost.allocations, row.inclusiveCost.temporary,
-                       round(float(row.inclusiveCost.temporary) * 100.f * 100.f / row.inclusiveCost.allocations) / 100.f,
+                       round(float(row.inclusiveCost.temporary) * 100.f * 100.f / std::max(uint64_t(1), row.inclusiveCost.allocations)) / 100.f,
                        m_format.formatByteSize(row.inclusiveCost.peak), m_format.formatByteSize(row.inclusiveCost.leaked));
         stream << '\n';
         stream << i18n("self: allocated %1 over %2 calls (%3 temporary, i.e. %4%), peak at %5, leaked %6",
                        m_format.formatByteSize(row.selfCost.allocated), row.selfCost.allocations, row.selfCost.temporary,
-                       round(float(row.selfCost.temporary) * 100.f * 100.f / row.selfCost.allocations) / 100.f,
+                       round(float(row.selfCost.temporary) * 100.f * 100.f / std::max(uint64_t(1), row.selfCost.allocations)) / 100.f,
                        m_format.formatByteSize(row.selfCost.peak), m_format.formatByteSize(row.selfCost.leaked));
         stream << '\n';
         stream << "</pre></qt>";