mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user