mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Ensure incorrectly coded counter KVP is read correctly.
Bug 798930 caused some counters to be saved as KVP double. If the correct int64_t value isn't found when reading, or if a double is encountered when loading the option dialog, get the double value and cast it to int64_t.
This commit is contained in:
@@ -512,10 +512,25 @@ GncOptionDB::load_from_kvp(QofBook* book) noexcept
|
|||||||
auto kvp = qof_book_get_option(book, &list_head);
|
auto kvp = qof_book_get_option(book, &list_head);
|
||||||
if (!kvp)
|
if (!kvp)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto set_double = [&option, kvp, &list_head]() {
|
||||||
|
/*counters might have been set as doubles
|
||||||
|
* because of
|
||||||
|
* https://bugs.gnucash.org/show_bug.cgi?id=798930. They
|
||||||
|
* should be int64_t.
|
||||||
|
*/
|
||||||
|
constexpr const char *counters{"counters"};
|
||||||
|
auto value{kvp->get<double>()};
|
||||||
|
if (strcmp(static_cast<char*>(list_head.data), counters) == 0)
|
||||||
|
option.set_value(static_cast<int64_t>(value));
|
||||||
|
else
|
||||||
|
option.set_value(value);
|
||||||
|
};
|
||||||
|
|
||||||
switch (kvp->get_type())
|
switch (kvp->get_type())
|
||||||
{
|
{
|
||||||
case KvpValue::Type::DOUBLE:
|
case KvpValue::Type::DOUBLE:
|
||||||
option.set_value(kvp->get<double>());
|
set_double();
|
||||||
break;
|
break;
|
||||||
case KvpValue::Type::INT64:
|
case KvpValue::Type::INT64:
|
||||||
option.set_value(kvp->get<int64_t>());
|
option.set_value(kvp->get<int64_t>());
|
||||||
|
|||||||
@@ -591,8 +591,13 @@ qof_book_get_counter (QofBook *book, const char *counter_name)
|
|||||||
value = kvp->get_slot({"counters", counter_name});
|
value = kvp->get_slot({"counters", counter_name});
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
/* found it */
|
auto int_value{value->get<int64_t>()};
|
||||||
return value->get<int64_t>();
|
/* Might be a double because of
|
||||||
|
* https://bugs.gnucash.org/show_bug.cgi?id=798930
|
||||||
|
*/
|
||||||
|
if (!int_value)
|
||||||
|
int_value = static_cast<int64_t>(value->get<double>());
|
||||||
|
return int_value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user