=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/dc/bcode.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- src/usr.bin/dc/bcode.c 2004/10/18 07:49:00 1.24 +++ src/usr.bin/dc/bcode.c 2004/12/01 08:29:38 1.25 @@ -1,4 +1,4 @@ -/* $OpenBSD: bcode.c,v 1.24 2004/10/18 07:49:00 otto Exp $ */ +/* $OpenBSD: bcode.c,v 1.25 2004/12/01 08:29:38 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek @@ -17,7 +17,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: bcode.c,v 1.24 2004/10/18 07:49:00 otto Exp $"; +static const char rcsid[] = "$OpenBSD: bcode.c,v 1.25 2004/12/01 08:29:38 otto Exp $"; #endif /* not lint */ #include @@ -101,7 +101,7 @@ static void bmod(void); static void bdivmod(void); static void bexp(void); -static bool bsqrt_stop(const BIGNUM *, const BIGNUM *); +static bool bsqrt_stop(const BIGNUM *, const BIGNUM *, u_int *); static void bsqrt(void); static void not(void); static void equal_numbers(void); @@ -1238,7 +1238,7 @@ } static bool -bsqrt_stop(const BIGNUM *x, const BIGNUM *y) +bsqrt_stop(const BIGNUM *x, const BIGNUM *y, u_int *onecount) { BIGNUM *r; bool ret; @@ -1246,9 +1246,11 @@ r = BN_new(); bn_checkp(r); bn_check(BN_sub(r, x, y)); - ret = BN_is_one(r) || BN_is_zero(r); + if (BN_is_one(r)) + (*onecount)++; + ret = BN_is_zero(r); BN_free(r); - return ret; + return ret || *onecount > 1; } static void @@ -1257,9 +1259,10 @@ struct number *n; struct number *r; BIGNUM *x, *y; - u_int scale; + u_int scale, onecount; BN_CTX *ctx; + onecount = 0; n = pop_number(); if (n == NULL) { return; @@ -1284,7 +1287,7 @@ bn_check(BN_div(x, NULL, n->number, x, ctx)); bn_check(BN_add(x, x, y)); bn_check(BN_rshift1(x, x)); - if (bsqrt_stop(x, y)) + if (bsqrt_stop(x, y, &onecount)) break; } r = bmalloc(sizeof(*r));