From: Andre Noll Date: Tue, 15 Mar 2016 19:41:37 +0000 (+0100) Subject: mood.c: Avoid integer overflow. X-Git-Tag: v0.5.6~45^2~5 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=58566e1535a0c47ce59570598885ccabc75891bf 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. --- 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)