diff --git a/libgnucash/engine/gnc-pricedb.c b/libgnucash/engine/gnc-pricedb.c index 102c2d947b..a39ba7e104 100644 --- a/libgnucash/engine/gnc-pricedb.c +++ b/libgnucash/engine/gnc-pricedb.c @@ -2196,7 +2196,7 @@ gnc_pricedb_nth_price (GNCPriceDB *db, merged currency list. */ GList **price_array = (GList **)g_new(gpointer, num_currencies); GList **next_list; - int i, j, k; + int i, j; GHashTableIter iter; gpointer key, value; @@ -2208,16 +2208,14 @@ gnc_pricedb_nth_price (GNCPriceDB *db, price_array[i] = value; } - /* Iterate up to n times (there are i prices, so going past i will run off the end of the array) to get the nth price, each time finding the currency - with the latest price */ - for (k = 0; k <= n && k < i; ++k) + for (i = 0; i <= n; ++i) { next_list = NULL; - for (j = 0; j < i; ++j) + for (j = 0; j < num_currencies; ++j) { /* Save this entry if it's the first one or later than the saved one. */ - if (price_array[k] != NULL && + if (price_array[j] != NULL && (next_list == NULL || *next_list == NULL || compare_prices_by_date((*next_list)->data, (price_array[j])->data) > 0)) {