Skip to content

Commit

Permalink
[account.cpp] log warnings if acct==nullptr instead of returning early
Browse files Browse the repository at this point in the history
calling these functions with acct==nullptr should indicate bad code.
  • Loading branch information
christopherlam committed Oct 14, 2024
1 parent 7383fb5 commit e52a405
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion libgnucash/engine/Account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3904,7 +3904,8 @@ xaccAccountGetNoclosingBalanceChangeInCurrencyForPeriod (Account *acc, time64 t1
const SplitsVec
xaccAccountGetSplits (const Account *account)
{
return GNC_IS_ACCOUNT(account) ? GET_PRIVATE(account)->splits : SplitsVec{};
g_return_val_if_fail (GNC_IS_ACCOUNT(account), SplitsVec{});
return GET_PRIVATE(account)->splits;
}

SplitList *
Expand All @@ -3919,6 +3920,7 @@ xaccAccountGetSplitList (const Account *acc)
size_t
xaccAccountGetSplitsSize (const Account *account)
{
g_return_val_if_fail (GNC_IS_ACCOUNT(account), 0);
return GNC_IS_ACCOUNT(account) ? GET_PRIVATE(account)->splits.size() : 0;
}

Expand Down Expand Up @@ -3994,12 +3996,14 @@ xaccAccountForEachLot(const Account *acc,
gboolean
xaccAccountGetTaxRelated (const Account *acc)
{
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), false);
return get_kvp_boolean_path(acc, {"tax-related"});
}

void
xaccAccountSetTaxRelated (Account *acc, gboolean tax_related)
{
g_return_if_fail(GNC_IS_ACCOUNT(acc));
set_kvp_boolean_path(acc, {"tax-related"}, tax_related);
}

Expand All @@ -4013,6 +4017,7 @@ xaccAccountGetTaxUSCode (const Account *acc)
void
xaccAccountSetTaxUSCode (Account *acc, const char *code)
{
g_return_if_fail(GNC_IS_ACCOUNT(acc));
set_kvp_string_path (acc, {"tax-US", "code"}, code);
}

Expand Down Expand Up @@ -4102,6 +4107,7 @@ xaccAccountSetAppendText (Account *acc, gboolean val)
gboolean
xaccAccountGetIsOpeningBalance (const Account *acc)
{
g_return_val_if_fail (GNC_IS_ACCOUNT(acc), false);
if (GET_PRIVATE(acc)->type != ACCT_TYPE_EQUITY)
return false;

Expand All @@ -4111,6 +4117,7 @@ xaccAccountGetIsOpeningBalance (const Account *acc)
void
xaccAccountSetIsOpeningBalance (Account *acc, gboolean val)
{
g_return_if_fail (GNC_IS_ACCOUNT(acc));
if (GET_PRIVATE(acc)->type != ACCT_TYPE_EQUITY)
return;
set_kvp_string_path(acc, {"equity-type"}, val ? "opening-balance" : nullptr);
Expand Down

0 comments on commit e52a405

Please sign in to comment.