Prevent integer overflow when computing percents in CostRepartitionBanner

This commit is contained in:
Grégory Soutadé 2017-11-01 20:37:51 +01:00
parent 7761fbac00
commit 0d929c8b92

View File

@ -151,7 +151,7 @@ void CostRepartitionBanner::UpdateCosts(int *categoriesValues, int totalDebit)
{ {
int i; int i;
User* user = _kiss->GetUser(); User* user = _kiss->GetUser();
int value, percents; unsigned long value, percents, utotalDebit = totalDebit;
QString v; QString v;
QPieSeries* series = (QPieSeries*) (_pie->series()[0]); QPieSeries* series = (QPieSeries*) (_pie->series()[0]);
QList<QtCharts::QPieSlice*> slices = series->slices(); QList<QtCharts::QPieSlice*> slices = series->slices();
@ -159,7 +159,9 @@ void CostRepartitionBanner::UpdateCosts(int *categoriesValues, int totalDebit)
for(i=0; i<user->GetCategoriesNumber(); i++) for(i=0; i<user->GetCategoriesNumber(); i++)
{ {
if (totalDebit != 0) if (totalDebit != 0)
percents = (categoriesValues[i]*100)/totalDebit; {
percents = ((categoriesValues[i]*(unsigned long)100))/utotalDebit;
}
else else
percents = 0.0; percents = 0.0;