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.
This commit is contained in:
John Ralls
2018-06-08 16:23:43 -07:00
parent dc7135920b
commit 6f0a3c4345

View File

@@ -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