Skip to content

Commit

Permalink
Merge Simon Arlott's 'static-analysis' into stable.
Browse files Browse the repository at this point in the history
  • Loading branch information
jralls committed Jun 24, 2023
2 parents ba7b260 + cdf0a37 commit 4768c31
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 122 deletions.
2 changes: 1 addition & 1 deletion gnucash/gnome-utils/dialog-account.c
Original file line number Diff line number Diff line change
Expand Up @@ -2232,7 +2232,7 @@ gnc_account_renumber_update_examples (RenumberDialog *data)
gtk_label_set_text (GTK_LABEL(data->example1), str);
g_free (str);

if (strlen (prefix))
if (prefix && *prefix)
str = g_strdup_printf ("%s-%0*d", prefix, num_digits,
interval * data->num_children);
else
Expand Down
2 changes: 1 addition & 1 deletion gnucash/gnome-utils/gnc-main-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3751,7 +3751,6 @@ gnc_main_window_update_menu_and_toolbar (GncMainWindow *window,
const gchar *menu_qualifier;

GMenuModel *menu_model_part;
GncMenuModelSearch *gsm = g_new0 (GncMenuModelSearch, 1);
#ifdef MAC_INTEGRATION
auto theApp{static_cast<GtkosxApplication *>(g_object_new(GTKOSX_TYPE_APPLICATION, nullptr))};
#endif
Expand Down Expand Up @@ -3792,6 +3791,7 @@ gnc_main_window_update_menu_and_toolbar (GncMainWindow *window,
gnc_menubar_model_remove_items_with_attrib (priv->menubar_model,
GNC_MENU_ATTRIBUTE_TEMPORARY);

GncMenuModelSearch *gsm = g_new0 (GncMenuModelSearch, 1);
for (gint i = 0; ui_updates[i]; i++)
{
gchar *menu_name;
Expand Down
2 changes: 1 addition & 1 deletion gnucash/gnome/window-autoclear.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ gnc_autoclear_window_ok_cb (GtkWidget *widget,
AutoClearWindow *data)
{
GList *toclear_list = NULL;
gnc_numeric toclear_value;
gnc_numeric toclear_value = gnc_numeric_error (GNC_ERROR_ARG);
gchar *errmsg = NULL;
GError* error = NULL;

Expand Down
2 changes: 1 addition & 1 deletion gnucash/import-export/qif-imp/dialog-account-picker.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer user_data)
QIFAccountPickerDialog * wind = user_data;
GtkTreeModel *model;
GtkTreeIter iter;
gboolean placeholder;
gboolean placeholder = TRUE;

if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection
(wind->treeview), &model, &iter))
Expand Down
1 change: 1 addition & 0 deletions gnucash/register/ledger-core/split-register-load.c
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ gnc_split_register_load (SplitRegister* reg, GList* slist,
{
VirtualCellLocation vc_loc;
vc_loc.virt_row = 0;
vc_loc.virt_col = 0;
gnc_split_register_show_trans (reg, vc_loc);
}
else
Expand Down
2 changes: 1 addition & 1 deletion gnucash/register/ledger-core/split-register.c
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,7 @@ gnc_split_register_save_to_copy_buffer (SplitRegister *reg,

if (!other_fs)
{
if (g_list_length (ft->m_splits) == 1)
if (ft && g_list_length (ft->m_splits) == 1)
{
Split* temp_split;

Expand Down
2 changes: 1 addition & 1 deletion gnucash/register/register-gnome/gnucash-style.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ set_dimensions_pass_two (GnucashSheet *sheet, int default_width)

width = 0;
num_cols = cursor->num_cols;
widths = g_new (int, num_cols);
widths = g_new0 (int, num_cols);

/* find header widths */
for (col = 0; col < num_cols; col++)
Expand Down
5 changes: 4 additions & 1 deletion libgnucash/app-utils/gnc-quotes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ void
GncQuotesImpl::report (const char* source, const StrVec& commodities,
bool verbose)
{
bool is_currency{source && strcmp(source, "currency") == 0};
if (!source)
throw (GncQuoteException(bl::translate("GncQuotes::Report called with no source.")));

bool is_currency{strcmp(source, "currency") == 0};
m_failures.clear();
if (commodities.empty())
{
Expand Down
6 changes: 1 addition & 5 deletions libgnucash/backend/xml/gnc-bill-term-xml-v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,7 @@ static gboolean
set_numeric (xmlNodePtr node, GncBillTerm* term,
void (*func) (GncBillTerm*, gnc_numeric))
{
gnc_numeric* num = dom_tree_to_gnc_numeric (node);
g_return_val_if_fail (num, FALSE);

func (term, *num);
g_free (num);
func (term, dom_tree_to_gnc_numeric (node));
return TRUE;
}

Expand Down
16 changes: 2 additions & 14 deletions libgnucash/backend/xml/gnc-customer-xml-v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,29 +289,17 @@ static gboolean
customer_discount_handler (xmlNodePtr node, gpointer cust_pdata)
{
struct customer_pdata* pdata = static_cast<decltype (pdata)> (cust_pdata);
gnc_numeric* val;

val = dom_tree_to_gnc_numeric (node);
g_return_val_if_fail (val, FALSE);

gncCustomerSetDiscount (pdata->customer, *val);
g_free (val);

gncCustomerSetDiscount (pdata->customer, dom_tree_to_gnc_numeric (node));
return TRUE;
}

static gboolean
customer_credit_handler (xmlNodePtr node, gpointer cust_pdata)
{
struct customer_pdata* pdata = static_cast<decltype (pdata)> (cust_pdata);
gnc_numeric* val;

val = dom_tree_to_gnc_numeric (node);
g_return_val_if_fail (val, FALSE);

gncCustomerSetCredit (pdata->customer, *val);
g_free (val);

gncCustomerSetCredit (pdata->customer, dom_tree_to_gnc_numeric (node));
return TRUE;
}

Expand Down
14 changes: 2 additions & 12 deletions libgnucash/backend/xml/gnc-employee-xml-v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,27 +229,17 @@ static gboolean
employee_workday_handler (xmlNodePtr node, gpointer employee_pdata)
{
struct employee_pdata* pdata = static_cast<decltype (pdata)> (employee_pdata);
gnc_numeric* val;

val = dom_tree_to_gnc_numeric (node);
g_return_val_if_fail (val, FALSE);
gncEmployeeSetWorkday (pdata->employee, *val);
g_free (val);

gncEmployeeSetWorkday (pdata->employee, dom_tree_to_gnc_numeric (node));
return TRUE;
}

static gboolean
employee_rate_handler (xmlNodePtr node, gpointer employee_pdata)
{
struct employee_pdata* pdata = static_cast<decltype (pdata)> (employee_pdata);
gnc_numeric* val;

val = dom_tree_to_gnc_numeric (node);
g_return_val_if_fail (val, FALSE);
gncEmployeeSetRate (pdata->employee, *val);
g_free (val);

gncEmployeeSetRate (pdata->employee, dom_tree_to_gnc_numeric (node));
return TRUE;
}

Expand Down
6 changes: 1 addition & 5 deletions libgnucash/backend/xml/gnc-entry-xml-v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,7 @@ static inline gboolean
set_numeric (xmlNodePtr node, GncEntry* entry,
void (*func) (GncEntry* entry, gnc_numeric num))
{
gnc_numeric* num = dom_tree_to_gnc_numeric (node);
g_return_val_if_fail (num, FALSE);

func (entry, *num);
g_free (num);
func (entry, dom_tree_to_gnc_numeric (node));
return TRUE;
}

Expand Down
5 changes: 1 addition & 4 deletions libgnucash/backend/xml/gnc-invoice-xml-v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,8 @@ static gboolean
invoice_tochargeamt_handler (xmlNodePtr node, gpointer invoice_pdata)
{
struct invoice_pdata* pdata = static_cast<decltype (pdata)> (invoice_pdata);
gnc_numeric* num = dom_tree_to_gnc_numeric (node);
g_return_val_if_fail (num, FALSE);

gncInvoiceSetToChargeAmount (pdata->invoice, *num);
g_free (num);
gncInvoiceSetToChargeAmount (pdata->invoice, dom_tree_to_gnc_numeric (node));
return TRUE;
}

Expand Down
5 changes: 1 addition & 4 deletions libgnucash/backend/xml/gnc-pricedb-xml-v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ price_parse_xml_sub_node (GNCPrice* p, xmlNodePtr sub_node, QofBook* book)
}
else if (g_strcmp0 ("price:value", (char*)sub_node->name) == 0)
{
gnc_numeric* value = dom_tree_to_gnc_numeric (sub_node);
if (!value) return FALSE;
gnc_price_set_value (p, *value);
g_free (value);
gnc_price_set_value (p, dom_tree_to_gnc_numeric (sub_node));
}
gnc_price_commit_edit (p);
return TRUE;
Expand Down
5 changes: 1 addition & 4 deletions libgnucash/backend/xml/gnc-tax-table-xml-v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,8 @@ static gboolean
ttentry_amount_handler (xmlNodePtr node, gpointer ttentry_pdata)
{
struct ttentry_pdata* pdata = static_cast<decltype (pdata)> (ttentry_pdata);
gnc_numeric* num = dom_tree_to_gnc_numeric (node);
g_return_val_if_fail (num, FALSE);

gncTaxTableEntrySetAmount (pdata->ttentry, *num);
g_free (num);
gncTaxTableEntrySetAmount (pdata->ttentry, dom_tree_to_gnc_numeric (node));
return TRUE;
}

Expand Down
10 changes: 2 additions & 8 deletions libgnucash/backend/xml/gnc-transaction-xml-v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,8 @@ static inline gboolean
set_spl_gnc_num (xmlNodePtr node, Split* spl,
void (*func) (Split* spl, gnc_numeric gn))
{
gnc_numeric* num = dom_tree_to_gnc_numeric (node);
g_return_val_if_fail (num, FALSE);

func (spl, *num);

g_free (num);

return FALSE;
func (spl, dom_tree_to_gnc_numeric (node));
return TRUE;
}

static gboolean
Expand Down
5 changes: 1 addition & 4 deletions libgnucash/backend/xml/io-gncxml-v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2967,10 +2967,7 @@ price_parse_xml_sub_node (GNCPrice* p, xmlNodePtr sub_node, QofBook* book)
}
else if (g_strcmp0 ("price:value", (char*)sub_node->name) == 0)
{
gnc_numeric* value = dom_tree_to_gnc_numeric (sub_node);
if (!value) return FALSE;
gnc_price_set_value (p, *value);
g_free (value);
gnc_price_set_value (p, dom_tree_to_gnc_numeric (sub_node));
}
gnc_price_commit_edit (p);
return TRUE;
Expand Down
11 changes: 8 additions & 3 deletions libgnucash/backend/xml/io-gncxml-v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1602,14 +1602,19 @@ gnc_book_write_to_xml_file_v2 (QofBook* book, const char* filename,
return false;

/* Try to write as much as possible */
success = (gnc_book_write_to_xml_filehandle_v2 (book, file));
if (!gnc_book_write_to_xml_filehandle_v2 (book, file))
success = false;

/* Close the output stream */
success = ! (fclose (file));
if (fclose (file))
success = false;

/* Optionally wait for parallel compression threads */
if (thread)
success = g_thread_join (thread) != nullptr;
{
if (g_thread_join (thread) != nullptr)
success = false;
}

return success;
}
Expand Down
26 changes: 7 additions & 19 deletions libgnucash/backend/xml/sixtp-dom-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,7 @@ dom_tree_to_double_kvp_value (xmlNodePtr node)
static KvpValue*
dom_tree_to_numeric_kvp_value (xmlNodePtr node)
{
gnc_numeric* danum;
KvpValue* ret = NULL;

danum = dom_tree_to_gnc_numeric (node);

if (danum)
{
ret = new KvpValue {*danum};
}

g_free (danum);

return ret;
return new KvpValue {dom_tree_to_gnc_numeric (node)};
}

static KvpValue*
Expand Down Expand Up @@ -514,19 +502,19 @@ dom_tree_to_text (xmlNodePtr tree)
return result;
}

gnc_numeric*
gnc_numeric
dom_tree_to_gnc_numeric (xmlNodePtr node)
{
gchar* content = dom_tree_to_text (node);
if (!content)
return NULL;
return gnc_numeric_zero ();

gnc_numeric *ret = g_new (gnc_numeric, 1);
gnc_numeric num;
if (!string_to_gnc_numeric (content, &num))
num = gnc_numeric_zero ();

if (!string_to_gnc_numeric (content, ret))
*ret = gnc_numeric_zero ();
g_free (content);
return ret;
return num;
}


Expand Down
2 changes: 1 addition & 1 deletion libgnucash/backend/xml/sixtp-dom-parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Recurrence* dom_tree_to_recurrence (xmlNodePtr node);
time64 dom_tree_to_time64 (xmlNodePtr node);
gboolean dom_tree_valid_time64 (time64 ts, const xmlChar* name);
GDate* dom_tree_to_gdate (xmlNodePtr node);
gnc_numeric* dom_tree_to_gnc_numeric (xmlNodePtr node);
gnc_numeric dom_tree_to_gnc_numeric (xmlNodePtr node);
gchar* dom_tree_to_text (xmlNodePtr tree);
gboolean string_to_binary (const gchar* str, void** v, guint64* data_len);
gboolean dom_tree_create_instance_slots (xmlNodePtr node, QofInstance* inst);
Expand Down
18 changes: 3 additions & 15 deletions libgnucash/backend/xml/test/test-dom-converters1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ static const char*
test_gnc_nums_internal (gnc_numeric to_test)
{
const char* ret = NULL;
gnc_numeric* to_compare = NULL;
xmlNodePtr to_gen = NULL;

to_gen = gnc_numeric_to_dom_tree ("test-num", &to_test);
Expand All @@ -173,24 +172,13 @@ test_gnc_nums_internal (gnc_numeric to_test)
}
else
{
to_compare = dom_tree_to_gnc_numeric (to_gen);
if (!to_compare)
gnc_numeric to_compare = dom_tree_to_gnc_numeric (to_gen);
if (!gnc_numeric_equal (to_test, to_compare))
{
ret = "no gnc_numeric parsed";
}
else
{
if (!gnc_numeric_equal (to_test, *to_compare))
{
ret = "numerics compared different";
}
ret = "numerics compared different";
}
}

if (to_compare)
{
g_free (to_compare);
}
if (to_gen)
{
xmlFreeNode (to_gen);
Expand Down

0 comments on commit 4768c31

Please sign in to comment.