jcs's openbsd hax
openbsd

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

tb 2fde6ebb a26544ef

+4 -4
+4 -4
games/factor/factor.c
··· 1 - /* $OpenBSD: factor.c,v 1.29 2016/08/14 18:34:48 guenther Exp $ */ 1 + /* $OpenBSD: factor.c,v 1.30 2016/09/01 10:48:38 tb Exp $ */ 2 2 /* $NetBSD: factor.c,v 1.5 1995/03/23 08:28:07 cgd Exp $ */ 3 3 4 4 /* ··· 75 75 76 76 static void pr_fact(u_int64_t); /* print factors of a value */ 77 77 static void pr_bigfact(u_int64_t); 78 - static u_int32_t usqrt(u_int64_t); 78 + static u_int64_t usqrt(u_int64_t); 79 79 static void __dead usage(void); 80 80 81 81 int ··· 284 284 } 285 285 286 286 /* Code taken from ping.c */ 287 - static u_int32_t 287 + static u_int64_t 288 288 usqrt(u_int64_t n) 289 289 { 290 290 u_int64_t y, x = 1; ··· 299 299 x /= 2; 300 300 } while (((y < x) && (x - y) > 1) || (y - x) > 1); 301 301 302 - return (u_int32_t)x; 302 + return x; 303 303 } 304 304 305 305 static void __dead