From 55856c63dd55e44c0c477266bf6954f0e6d571e5 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Fri, 22 May 2026 21:13:54 +0800 Subject: [PATCH] [gnc-budget.cpp] null check arguments *before* accessing them --- libgnucash/engine/gnc-budget.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libgnucash/engine/gnc-budget.cpp b/libgnucash/engine/gnc-budget.cpp index ec8638df0c..7317833842 100644 --- a/libgnucash/engine/gnc-budget.cpp +++ b/libgnucash/engine/gnc-budget.cpp @@ -541,6 +541,9 @@ void gnc_budget_set_account_period_value(GncBudget *budget, const Account *account, guint period_num, gnc_numeric val) { + g_return_if_fail (budget != nullptr); + g_return_if_fail (account != nullptr); + /* Watch out for an off-by-one error here: * period_num starts from 0 while num_periods starts from 1 */ if (period_num >= GET_PRIVATE(budget)->num_periods) @@ -549,9 +552,6 @@ gnc_budget_set_account_period_value(GncBudget *budget, const Account *account, return; } - g_return_if_fail (budget != nullptr); - g_return_if_fail (account != nullptr); - auto& perioddata = get_perioddata (budget, account, period_num); auto budget_kvp { QOF_INSTANCE (budget)->kvp_data }; auto path = make_period_data_path (account, period_num); @@ -600,6 +600,9 @@ void gnc_budget_set_account_period_note(GncBudget *budget, const Account *account, guint period_num, const gchar *note) { + g_return_if_fail (budget != nullptr); + g_return_if_fail (account != nullptr); + /* Watch out for an off-by-one error here: * period_num starts from 0 while num_periods starts from 1 */ if (period_num >= GET_PRIVATE(budget)->num_periods) @@ -608,9 +611,6 @@ gnc_budget_set_account_period_note(GncBudget *budget, const Account *account, return; } - g_return_if_fail (budget != nullptr); - g_return_if_fail (account != nullptr); - auto& perioddata = get_perioddata (budget, account, period_num); auto budget_kvp { QOF_INSTANCE (budget)->kvp_data }; auto path = make_period_note_path (account, period_num);