From 6f39c0c26e3cdb52d2af2781a781eadb988ebe43 Mon Sep 17 00:00:00 2001 From: Derek Atkins Date: Mon, 24 Dec 2007 21:18:09 +0000 Subject: [PATCH] (#492137) Re-apply r16619 and make a change to the test harness to actually get the checks to pass with r16690. This was an overflow in the test harness. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16716 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/cap-gains.c | 6 +++--- src/engine/test-core/test-engine-stuff.c | 14 ++++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/engine/cap-gains.c b/src/engine/cap-gains.c index 1988651a3e..e3fa8b70fc 100644 --- a/src/engine/cap-gains.c +++ b/src/engine/cap-gains.c @@ -168,7 +168,7 @@ finder_helper (GNCLot *lot, gpointer user_data) static inline GNCLot * xaccAccountFindOpenLot (Account *acc, gnc_numeric sign, gnc_commodity *currency, - guint64 guess, + gint64 guess, gboolean (*date_pred)(Timespec, Timespec)) { struct find_lot_s es; @@ -195,7 +195,7 @@ xaccAccountFindEarliestOpenLot (Account *acc, gnc_numeric sign, sign.denom); lot = xaccAccountFindOpenLot (acc, sign, currency, - G_MAXUINT64, earliest_pred); + G_MAXINT64, earliest_pred); LEAVE ("found lot=%p %s baln=%s", lot, gnc_lot_get_title (lot), gnc_num_dbg_to_string(gnc_lot_get_balance(lot))); return lot; @@ -210,7 +210,7 @@ xaccAccountFindLatestOpenLot (Account *acc, gnc_numeric sign, sign.num, sign.denom); lot = xaccAccountFindOpenLot (acc, sign, currency, - 0, latest_pred); + G_MININT64, latest_pred); LEAVE ("found lot=%p %s", lot, gnc_lot_get_title (lot)); return lot; } diff --git a/src/engine/test-core/test-engine-stuff.c b/src/engine/test-core/test-engine-stuff.c index a3f0313708..855ed2c45f 100644 --- a/src/engine/test-core/test-engine-stuff.c +++ b/src/engine/test-core/test-engine-stuff.c @@ -447,9 +447,9 @@ get_random_gnc_numeric(void) } else { - gint64 norm = RAND_IN_RANGE (8ULL); + gint64 norm = RAND_IN_RANGE (7ULL); - /* multiple of 10, between 1 and 10 million */ + /* multiple of 10, between 1 and 1 million */ deno = 1; while (norm) { @@ -460,8 +460,14 @@ get_random_gnc_numeric(void) /* Arbitrary random numbers can cause pointless overflow * during calculations. Limit dynamic range in hopes - * of avoiding overflow. */ - numer = get_random_gint64()/1000000; + * of avoiding overflow. Right now limit it to approx 2^48. + * The initial division is to help us down towards the range. + * The loop is to "make sure" we get there. We might + * want to make this dependent on "deno" in the future. + */ + do { + numer = get_random_gint64()/1000000; + } while ((numer >> 31) > 0x1FFFF); if (0 == numer) numer = 1; /* Make sure we have a non-zero denominator */ if (0 == deno) deno = 1;