diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2016-09-01 10:48:39 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2016-09-01 10:48:39 +0000 |
commit | ee53dd87f9d99cedb38af9fce16ff4fca4cbab89 (patch) | |
tree | f4edfeb85014650bf4fc32d42b2c7d0407ec96d3 /games/factor/factor.c | |
parent | 97072d957f586519f005508243061c570f4614f9 (diff) |
In 32 bits sqrt(val) + 1 can overflow, so some big primes still
aren't recognized as such, for example 18446744073709551577 given
in the commit message of factor.c r1.7 from NetBSD. Move the
return type of usqrt() from u_int32_t to u_int64_t.
ok guenther, tom, otto
Diffstat (limited to 'games/factor/factor.c')
-rw-r--r-- | games/factor/factor.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/games/factor/factor.c b/games/factor/factor.c index 4c1cfd4150e..b4ae0577c11 100644 --- a/games/factor/factor.c +++ b/games/factor/factor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: factor.c,v 1.29 2016/08/14 18:34:48 guenther Exp $ */ +/* $OpenBSD: factor.c,v 1.30 2016/09/01 10:48:38 tb Exp $ */ /* $NetBSD: factor.c,v 1.5 1995/03/23 08:28:07 cgd Exp $ */ /* @@ -75,7 +75,7 @@ extern const int pattern_size; static void pr_fact(u_int64_t); /* print factors of a value */ static void pr_bigfact(u_int64_t); -static u_int32_t usqrt(u_int64_t); +static u_int64_t usqrt(u_int64_t); static void __dead usage(void); int @@ -284,7 +284,7 @@ pr_bigfact(u_int64_t val) /* Factor this value. */ } /* Code taken from ping.c */ -static u_int32_t +static u_int64_t usqrt(u_int64_t n) { u_int64_t y, x = 1; @@ -299,7 +299,7 @@ usqrt(u_int64_t n) x /= 2; } while (((y < x) && (x - y) > 1) || (y - x) > 1); - return (u_int32_t)x; + return x; } static void __dead |