From 518dab24296bec3340512908845f9d0be186aa11 Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Fri, 9 Jun 2023 14:15:48 +0100 Subject: [PATCH] Valgrind: fix "Conditional jump depends on uninitialised value" - test-split-register-copy-ops - Don't save the address of a stack variable ==105765== Conditional jump or move depends on uninitialised value(s) ==105765== at 0x10E763: test_gnc_float_txn_to_txn_swap_accounts (utest-split-register-copy-ops.c:540) ==105765== by 0x5109675: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x510938A: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x510938A: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x510938A: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x5109BC9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x5103FFC: g_test_run (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x10BC6F: main (test-split-register.c:45) ==105765== ==105765== Conditional jump or move depends on uninitialised value(s) ==105765== at 0x4877C57: gnc_float_txn_to_txn_swap_accounts (split-register-copy-ops.c:433) ==105765== by 0x10E7E1: test_gnc_float_txn_to_txn_swap_accounts (utest-split-register-copy-ops.c:548) ==105765== by 0x5109675: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x510938A: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x510938A: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x510938A: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x5109BC9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x5103FFC: g_test_run (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x10BC6F: main (test-split-register.c:45) ==105765== ==105765== Conditional jump or move depends on uninitialised value(s) ==105765== at 0x10EFC1: test_gnc_float_txn_to_txn_swap_accounts (utest-split-register-copy-ops.c:589) ==105765== by 0x5109675: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x510938A: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x510938A: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x510938A: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x5109BC9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x5103FFC: g_test_run (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==105765== by 0x10BC6F: main (test-split-register.c:45) --- .../test/utest-split-register-copy-ops.c | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/gnucash/register/ledger-core/test/utest-split-register-copy-ops.c b/gnucash/register/ledger-core/test/utest-split-register-copy-ops.c index 69e946ae63c..09c94745149 100644 --- a/gnucash/register/ledger-core/test/utest-split-register-copy-ops.c +++ b/gnucash/register/ledger-core/test/utest-split-register-copy-ops.c @@ -528,9 +528,8 @@ test_gnc_float_txn_get_other_float_split (FlFixture *fixture, gconstpointer pDat void gnc_float_txn_to_txn_swap_accounts (const FloatingTxn *ft, Transaction *txn, Account *acct1, Account *acct2, gboolean do_commit)// C: 1 Local: 1:0:0 */ static void -test_gnc_float_txn_to_txn_swap_accounts (FlFixture *fixture, gconstpointer pData) +impl_test_gnc_float_txn_to_txn_swap_accounts (FlFixture *fixture, const SwapCommitPrefs *prefs) { - SwapCommitPrefs *prefs = (SwapCommitPrefs*)pData; Transaction *txn = xaccMallocTransaction (fixture->book); Account *sw_acct1 = NULL, *sw_acct2 = NULL; Account *exp_acct1 = fixture->acc1, *exp_acct2 = fixture->acc2; @@ -591,11 +590,37 @@ test_gnc_float_txn_to_txn_swap_accounts (FlFixture *fixture, gconstpointer pData xaccTransDestroy (txn); } +static void +test_gnc_float_txn_to_txn_swap_accounts_noswap_nocommit (FlFixture *fixture, gconstpointer pData) +{ + SwapCommitPrefs prefs = {FALSE, FALSE}; + impl_test_gnc_float_txn_to_txn_swap_accounts(fixture, &prefs); +} + +static void +test_gnc_float_txn_to_txn_swap_accounts_noswap_commit (FlFixture *fixture, gconstpointer pData) +{ + SwapCommitPrefs prefs = {FALSE, TRUE}; + impl_test_gnc_float_txn_to_txn_swap_accounts(fixture, &prefs); +} + +static void +test_gnc_float_txn_to_txn_swap_accounts_swap_commit (FlFixture *fixture, gconstpointer pData) +{ + SwapCommitPrefs prefs = {TRUE, TRUE}; + impl_test_gnc_float_txn_to_txn_swap_accounts(fixture, &prefs); +} + +static void +test_gnc_float_txn_to_txn_swap_accounts_swap_nocommit (FlFixture *fixture, gconstpointer pData) +{ + SwapCommitPrefs prefs = {TRUE, FALSE}; + impl_test_gnc_float_txn_to_txn_swap_accounts(fixture, &prefs); +} void test_suite_split_register_copy_ops (void) { - SwapCommitPrefs prefs; GNC_TEST_ADD (suitename, "gnc split to float split", Fixture, NULL, setup, test_gnc_split_to_float_split, teardown); GNC_TEST_ADD (suitename, "gnc float split to split", Fixture, NULL, setup, test_gnc_float_split_to_split, teardown); GNC_TEST_ADD (suitename, "gnc float txn to float txn", Fixture, NULL, setup, test_gnc_txn_to_float_txn, teardown); @@ -603,14 +628,9 @@ test_suite_split_register_copy_ops (void) GNC_TEST_ADD (suitename, "gnc float txn get float split", FlFixture, NULL, flsetup, test_gnc_float_txn_get_float_split, flteardown); GNC_TEST_ADD (suitename, "gnc float txn get other float split", FlFixture, NULL, flsetup, test_gnc_float_txn_get_other_float_split, flteardown); - prefs.swap_accts = FALSE; - prefs.docommit = FALSE; - GNC_TEST_ADD (suitename, "gnc float txn to txn noswap nocommit", FlFixture, &prefs, flsetup, test_gnc_float_txn_to_txn_swap_accounts, flteardown); - prefs.docommit = TRUE; - GNC_TEST_ADD (suitename, "gnc float txn to txn noswap commit", FlFixture, &prefs, flsetup, test_gnc_float_txn_to_txn_swap_accounts, flteardown); - prefs.swap_accts = TRUE; - GNC_TEST_ADD (suitename, "gnc float txn to txn swap commit", FlFixture, &prefs, flsetup, test_gnc_float_txn_to_txn_swap_accounts, flteardown); - prefs.docommit = FALSE; - GNC_TEST_ADD (suitename, "gnc float txn to txn swap nocommit", FlFixture, &prefs, flsetup, test_gnc_float_txn_to_txn_swap_accounts, flteardown); + GNC_TEST_ADD (suitename, "gnc float txn to txn noswap nocommit", FlFixture, NULL, flsetup, test_gnc_float_txn_to_txn_swap_accounts_noswap_nocommit, flteardown); + GNC_TEST_ADD (suitename, "gnc float txn to txn noswap commit", FlFixture, NULL, flsetup, test_gnc_float_txn_to_txn_swap_accounts_noswap_commit, flteardown); + GNC_TEST_ADD (suitename, "gnc float txn to txn swap commit", FlFixture, NULL, flsetup, test_gnc_float_txn_to_txn_swap_accounts_swap_commit, flteardown); + GNC_TEST_ADD (suitename, "gnc float txn to txn swap nocommit", FlFixture, NULL, flsetup, test_gnc_float_txn_to_txn_swap_accounts_swap_nocommit, flteardown); }