From bbfa378783abd382c04ea8ae7079a7190e199bde Mon Sep 17 00:00:00 2001 From: John Ralls Date: Thu, 2 Mar 2023 17:03:39 -0800 Subject: [PATCH] Don't crash and do pass tests. --- libgnucash/engine/Account.cpp | 4 ++-- libgnucash/engine/test/utest-Account.cpp | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp index 7846db1480..a599f158ea 100644 --- a/libgnucash/engine/Account.cpp +++ b/libgnucash/engine/Account.cpp @@ -2481,7 +2481,7 @@ set_kvp_string_path (Account *acc, std::vector const & path, g_return_if_fail(GNC_IS_ACCOUNT(acc)); xaccAccountBeginEdit(acc); - if (value) + if (value && *value) { GValue v = G_VALUE_INIT; g_value_init (&v, G_TYPE_STRING); @@ -2510,7 +2510,7 @@ get_kvp_string_path (const Account *acc, std::vector const & path, *v = G_VALUE_INIT; if (acc == NULL) return NULL; // how to check path is valid?? qof_instance_get_path_kvp (QOF_INSTANCE (acc), v, path); - return G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (v) : NULL; + return G_VALUE_HOLDS_STRING (v) ? g_value_get_string (v) : NULL; } static const char* diff --git a/libgnucash/engine/test/utest-Account.cpp b/libgnucash/engine/test/utest-Account.cpp index 6f380ee8b3..639c2b5d3f 100644 --- a/libgnucash/engine/test/utest-Account.cpp +++ b/libgnucash/engine/test/utest-Account.cpp @@ -19,6 +19,7 @@ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * * Boston, MA 02110-1301, USA gnu@gnu.org * ********************************************************************/ +#include #include #include @@ -1153,7 +1154,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData) g_assert_cmpstr (xaccAccountGetTaxUSCode (account), ==, "red"); xaccAccountSetTaxUSCode (account, ""); - g_assert_cmpstr (xaccAccountGetTaxUSCode (account), ==, ""); + g_assert_cmpstr (xaccAccountGetTaxUSCode (account), ==, nullptr); xaccAccountSetTaxUSCode (account, " "); g_assert_cmpstr (xaccAccountGetTaxUSCode (account), ==, " "); @@ -1171,7 +1172,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData) g_assert_cmpstr (xaccAccountGetTaxUSPayerNameSource (account), ==, "red"); xaccAccountSetTaxUSPayerNameSource (account, ""); - g_assert_cmpstr (xaccAccountGetTaxUSPayerNameSource (account), ==, ""); + g_assert_cmpstr (xaccAccountGetTaxUSPayerNameSource (account), ==, nullptr); xaccAccountSetTaxUSPayerNameSource (account, " "); g_assert_cmpstr (xaccAccountGetTaxUSPayerNameSource (account), ==, " "); @@ -1192,7 +1193,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData) g_assert_cmpstr (xaccAccountGetFilter (account), ==, "unset"); xaccAccountSetFilter (account, " unset "); - g_assert_cmpstr (xaccAccountGetFilter (account), ==, "unset"); + g_assert_cmpstr (xaccAccountGetFilter (account), ==, " unset "); xaccAccountSetFilter (account, ""); g_assert_cmpstr (xaccAccountGetFilter (account), ==, nullptr); @@ -1210,7 +1211,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData) g_assert_cmpstr (xaccAccountGetSortOrder (account), ==, "unset"); xaccAccountSetSortOrder (account, " unset "); - g_assert_cmpstr (xaccAccountGetSortOrder (account), ==, "unset"); + g_assert_cmpstr (xaccAccountGetSortOrder (account), ==, " unset "); xaccAccountSetSortOrder (account, ""); g_assert_cmpstr (xaccAccountGetSortOrder (account), ==, nullptr); @@ -1228,7 +1229,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData) g_assert_cmpstr (xaccAccountGetNotes (account), ==, "unset"); xaccAccountSetNotes (account, " unset "); - g_assert_cmpstr (xaccAccountGetNotes (account), ==, "unset"); + g_assert_cmpstr (xaccAccountGetNotes (account), ==, " unset "); xaccAccountSetNotes (account, ""); g_assert_cmpstr (xaccAccountGetNotes (account), ==, nullptr); @@ -1301,7 +1302,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData) g_assert_cmpstr (dxaccAccountGetPriceSrc (account), ==, "boo"); dxaccAccountSetPriceSrc (account, ""); - g_assert_cmpstr (dxaccAccountGetPriceSrc (account), ==, ""); + g_assert_cmpstr (dxaccAccountGetPriceSrc (account), ==, nullptr); dxaccAccountSetPriceSrc (account, nullptr); g_assert_cmpstr (dxaccAccountGetPriceSrc (account), ==, nullptr); @@ -1313,7 +1314,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData) g_assert_cmpstr (dxaccAccountGetQuoteTZ (account), ==, "boo"); dxaccAccountSetQuoteTZ (account, ""); - g_assert_cmpstr (dxaccAccountGetQuoteTZ (account), ==, ""); + g_assert_cmpstr (dxaccAccountGetQuoteTZ (account), ==, nullptr); dxaccAccountSetQuoteTZ (account, nullptr); g_assert_cmpstr (dxaccAccountGetQuoteTZ (account), ==, nullptr);