gnucash maint: Bug 795362 - Special variable "i" not parsed in function calls

John Ralls jralls at code.gnucash.org
Fri Jun 8 19:44:41 EDT 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/6f0a3c43 (commit)
	from  https://github.com/Gnucash/gnucash/commit/dc713592 (commit)



commit 6f0a3c4345161e3ae005afb6bf4c7c49486587a6
Author: John Ralls <jralls at ceridwen.us>
Date:   Fri Jun 8 16:23:43 2018 -0700

    Bug 795362 - Special variable "i" not parsed in function calls
    
    Limit the range of the random value to 1..1000 to prevent overflows,
    particularly in number-of-periods or number-of-years variables.
    
    While we're at it, g_random_int and g_random_int_range return ints so
    piping the result through gnc_double_to_numeric() doesn't make much
    sense. That's removed, we just construct a gnc_numeric.

diff --git a/libgnucash/app-utils/gnc-sx-instance-model.c b/libgnucash/app-utils/gnc-sx-instance-model.c
index 764ada1..4e07d04 100644
--- a/libgnucash/app-utils/gnc-sx-instance-model.c
+++ b/libgnucash/app-utils/gnc-sx-instance-model.c
@@ -328,9 +328,13 @@ gnc_sx_get_variables(SchedXaction *sx, GHashTable *var_hash)
 static void
 _set_var_to_random_value(gchar *key, GncSxVariable *var, gpointer unused_user_data)
 {
-    var->value = double_to_gnc_numeric(g_random_int() + 2, 1,
-                                       GNC_NUMERIC_RND_MASK
-                                       | GNC_HOW_RND_FLOOR);
+    /* This is used by dialog-sx-editor to plug in values as a simplistic way to
+     * check balances. One possible variable is the number of periods in a
+     * interest or future value calculation where the variable is used as an
+     * exponent, so we want the numbers to be monotonically > 0 and not so large
+     * that they'll cause overflows.
+     */
+    var->value = gnc_numeric_create(g_random_int_range(1, 1000), 1);
 }
 
 void



Summary of changes:
 libgnucash/app-utils/gnc-sx-instance-model.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)



More information about the gnucash-changes mailing list