From 4678b4cb75ae0ecaa36821d6d1f2a37263e2dfdc Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 2 Feb 2013 18:28:31 +0000 Subject: [PATCH] math: fix a signed integer overflow issue in the fast factorial computation function. --- src/math/real.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/math/real.cpp b/src/math/real.cpp index dca246b1..b4a43e92 100644 --- a/src/math/real.cpp +++ b/src/math/real.cpp @@ -763,10 +763,10 @@ template<> real pow(real const &x, real const &y) } } -static real fast_fact(int x) +static real fast_fact(unsigned int x) { real ret = real::R_1(); - int i = 1, multiplier = 1, exponent = 0; + unsigned int i = 1, multiplier = 1, exponent = 0; for (;;) { @@ -774,7 +774,7 @@ static real fast_fact(int x) /* Multiplication is a no-op if multiplier == 1 */ return ldexp(ret * multiplier, exponent); - int tmp = i; + unsigned int tmp = i; while ((tmp & 1) == 0) { tmp >>= 1;