gnucash maint: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Sat Nov 7 19:24:53 EST 2020
Updated via https://github.com/Gnucash/gnucash/commit/2290fa7c (commit)
via https://github.com/Gnucash/gnucash/commit/d03dc07b (commit)
from https://github.com/Gnucash/gnucash/commit/3bcf57e7 (commit)
commit 2290fa7c22d5c4f45b58968a58c4f0b8b21179ec
Author: John Ralls <jralls at ceridwen.us>
Date: Sat Nov 7 16:22:18 2020 -0800
Fix exception when converting to decimal values that reduce to N/1.
Before this the loop wouldn't terminate until the denominator had been
reduced to 0 and trying to create a GncRational with a 0 denominator
throws.
diff --git a/libgnucash/engine/gnc-numeric.cpp b/libgnucash/engine/gnc-numeric.cpp
index f9af38878..5e6773847 100644
--- a/libgnucash/engine/gnc-numeric.cpp
+++ b/libgnucash/engine/gnc-numeric.cpp
@@ -368,7 +368,7 @@ GncNumeric::to_decimal(unsigned int max_places) const
rr_num *= factor;
rr_den *= factor;
}
- while (!rr_num.isZero() && rr_num % 10 == 0)
+ while (!rr_num.isZero() && rr_num > 9 && rr_den > 9 && rr_num % 10 == 0)
{
rr_num /= 10;
rr_den /= 10;
diff --git a/libgnucash/engine/test/gtest-gnc-numeric.cpp b/libgnucash/engine/test/gtest-gnc-numeric.cpp
index 5cbe5c724..e194367bb 100644
--- a/libgnucash/engine/test/gtest-gnc-numeric.cpp
+++ b/libgnucash/engine/test/gtest-gnc-numeric.cpp
@@ -548,4 +548,16 @@ TEST(gnc_numeric_functions, test_conversion_to_decimal)
EXPECT_NO_THROW(r = c.to_decimal());
EXPECT_EQ(27434842, r.num());
EXPECT_EQ(100, r.denom());
+ GncNumeric d(11900000000, 85000000);
+ EXPECT_NO_THROW(r = d.to_decimal());
+ EXPECT_EQ(140, r.num());
+ EXPECT_EQ(1, r.denom());
+ GncNumeric e(11050000000, 65000000);
+ EXPECT_NO_THROW(r = e.to_decimal());
+ EXPECT_EQ(170, r.num());
+ EXPECT_EQ(1, r.denom());
+ GncNumeric f(5000000000, 50000000 );
+ EXPECT_NO_THROW(r = f.to_decimal());
+ EXPECT_EQ(100, r.num());
+ EXPECT_EQ(1, r.denom());
}
commit d03dc07b8d2bc701a5a9cdfc6928725b32aefd45
Author: John Ralls <jralls at ceridwen.us>
Date: Sat Nov 7 13:20:22 2020 -0800
Remove redundant and incorrectly named constant.
diff --git a/libgnucash/engine/gnc-timezone.cpp b/libgnucash/engine/gnc-timezone.cpp
index 6c03481d4..33f0609ec 100644
--- a/libgnucash/engine/gnc-timezone.cpp
+++ b/libgnucash/engine/gnc-timezone.cpp
@@ -460,14 +460,12 @@ namespace IANAParser
//Add in the tzinfo indexes consumed in the previous loop
start_index = info_index_zero + time_count;
- //Can't use sizeof(TZInfo) because it's padded out to 8 bytes.
- static const size_t tzinfo_size = 6;
- auto abbrev = start_index + type_count * tzinfo_size;
+ auto abbrev = start_index + type_count * ttinfo_size;
auto std_dist = abbrev + char_count;
auto gmt_dist = std_dist + type_count;
for(uint32_t index = 0; index < type_count; ++index)
{
- fb_index = start_index + index * tzinfo_size;
+ fb_index = start_index + index * ttinfo_size;
/* Use memcpy instead of static_cast to avoid memory alignment issues with chars */
TTInfo info{};
memcpy(&info, &fileblock[fb_index], ttinfo_size);
Summary of changes:
libgnucash/engine/gnc-numeric.cpp | 2 +-
libgnucash/engine/gnc-timezone.cpp | 6 ++----
libgnucash/engine/test/gtest-gnc-numeric.cpp | 12 ++++++++++++
3 files changed, 15 insertions(+), 5 deletions(-)
More information about the gnucash-changes
mailing list