From 58566e1535a0c47ce59570598885ccabc75891bf Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 15 Mar 2016 20:41:37 +0100 Subject: [PATCH] mood.c: Avoid integer overflow. The quadratic deviation qd can be very large, causing the multiplication n * qd to overflow. The new code avoids the multiplication at the cost of two calls to int_sqrt() instead of one. --- mood.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mood.c b/mood.c index 8e6a7665..e026c960 100644 --- a/mood.c +++ b/mood.c @@ -472,7 +472,7 @@ static int64_t normalized_value(int64_t x, int64_t n, int64_t sum, int64_t qd) { if (!n || !qd) return 0; - return 100 * (n * x - sum) / (int64_t)int_sqrt(n * qd); + return 100 * (n * x - sum) / (int64_t)int_sqrt(n) / (int64_t)int_sqrt(qd); } static long compute_num_played_score(struct afs_info *afsi) -- 2.39.2