projects
/
paraslash.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
7505e8b
)
mood.c: Avoid integer overflow.
author
Andre Noll
<maan@tuebingen.mpg.de>
Tue, 15 Mar 2016 19:41:37 +0000
(20:41 +0100)
committer
Andre Noll
<maan@tuebingen.mpg.de>
Tue, 15 Mar 2016 20:59:29 +0000
(21:59 +0100)
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
patch
|
blob
|
history
diff --git
a/mood.c
b/mood.c
index 8e6a7665f15e32bc5774c5539358ccaf0bcbc880..e026c960d5fd878cdca6350f3e74a40b85c338f8 100644
(file)
--- 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)