Skip to content

Commit

Permalink
Valgrind: fix "Conditional jump depends on uninitialised value" - tes…
Browse files Browse the repository at this point in the history
…t-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)
  • Loading branch information
richardcohen committed Jun 21, 2023
1 parent fa0824e commit 518dab2
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions gnucash/register/ledger-core/test/utest-split-register-copy-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -591,26 +590,47 @@ 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);
GNC_TEST_ADD (suitename, "gnc float txn to float txn cut semantics", Fixture, NULL, setup, test_gnc_txn_to_float_txn_cut_semantics, teardown);
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);

}

0 comments on commit 518dab2

Please sign in to comment.