lib_rank: fix potential integer overflow

This commit is contained in:
Thomas Schoebel-Theuer 2012-12-04 11:52:51 +01:00 committed by Thomas Schoebel-Theuer
parent 9126a3819e
commit 8ef65996cf
3 changed files with 6 additions and 6 deletions

View File

@ -48,14 +48,14 @@ EXPORT_SYMBOL_GPL(ranking_compute);
int ranking_select(struct rank_data rkd[], int rkd_count)
{
int res = -1;
int max = INT_MIN / 2;
long long max = LLONG_MIN / 2;
int i;
MARS_IO("rkd_count = %d\n", rkd_count);
for (i = 0; i < rkd_count; i++) {
struct rank_data *tmp = &rkd[i];
int rest = tmp->rkd_current_points;
long long rest = tmp->rkd_current_points;
if (rest <= 0)
continue;
//rest -= tmp->rkd_got;

View File

@ -16,10 +16,10 @@ struct rank_info {
struct rank_data {
// public readonly
int rkd_current_points;
long long rkd_current_points;
// private
int rkd_tmp;
int rkd_got;
long long rkd_tmp;
long long rkd_got;
};
/* Ranking phase.

View File

@ -2169,7 +2169,7 @@ int _do_ranking(struct trans_logger_brick *brick, struct rank_data rkd[])
#ifdef IO_DEBUGGING
for (i = 0; i < LOGGER_QUEUES; i++) {
MARS_IO("rkd[%d]: points = %d tmp = %d got = %d\n", i, rkd[i].rkd_current_points, rkd[i].rkd_tmp, rkd[i].rkd_got);
MARS_IO("rkd[%d]: points = %lld tmp = %lld got = %lld\n", i, rkd[i].rkd_current_points, rkd[i].rkd_tmp, rkd[i].rkd_got);
}
MARS_IO("res = %d\n", res);
#endif