gnucash maint: Bug 797853 - Crash on 'Save As' in MacOS Mojave and Gnucash 4
John Ralls
jralls at code.gnucash.org
Fri Jul 10 18:54:22 EDT 2020
Updated via https://github.com/Gnucash/gnucash/commit/edd7efd9 (commit)
from https://github.com/Gnucash/gnucash/commit/1f95d3a7 (commit)
commit edd7efd95165d7fef71f5757165712b87ddd82a8
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Jul 10 15:52:31 2020 -0700
Bug 797853 - Crash on 'Save As' in MacOS Mojave and Gnucash 4
Check and handle null books throughout GnuCash. Tests are left alone
because they should fail if there's no book.
diff --git a/gnucash/gnome-utils/gnc-tree-view-account.c b/gnucash/gnome-utils/gnc-tree-view-account.c
index 960f098e1..8c5463194 100644
--- a/gnucash/gnome-utils/gnc-tree-view-account.c
+++ b/gnucash/gnome-utils/gnc-tree-view-account.c
@@ -2507,6 +2507,7 @@ tree_restore_expanded_row (GncTreeViewAccount *view,
QofBook *book;
book = qof_session_get_book(gnc_get_current_session());
+ g_return_if_fail(book);
account = gnc_account_lookup_by_full_name(gnc_book_get_root_account(book),
account_name);
if (account)
@@ -2529,6 +2530,7 @@ tree_restore_selected_row (GncTreeViewAccount *view,
QofBook *book;
book = qof_session_get_book(gnc_get_current_session());
+ g_return_if_fail(book);
account = gnc_account_lookup_by_full_name(gnc_book_get_root_account(book),
account_name);
if (account)
diff --git a/gnucash/gnome/dialog-invoice.c b/gnucash/gnome/dialog-invoice.c
index 7787fdc26..8eb5c0c05 100644
--- a/gnucash/gnome/dialog-invoice.c
+++ b/gnucash/gnome/dialog-invoice.c
@@ -3556,6 +3556,12 @@ gnc_invoice_show_docs_due (GtkWindow *parent, QofBook *book, double days_in_adva
{ NULL },
};
+ if (!book)
+ {
+ PERR("No book, no due invoices.");
+ return NULL;
+ }
+
/* Create the param list (in reverse order) */
if (param_list == NULL)
{
diff --git a/gnucash/gnome/dialog-price-editor.c b/gnucash/gnome/dialog-price-editor.c
index 3d9e62db2..f5b455a0b 100644
--- a/gnucash/gnome/dialog-price-editor.c
+++ b/gnucash/gnome/dialog-price-editor.c
@@ -653,10 +653,12 @@ GNCPrice *
gnc_price_edit_by_guid (GtkWidget * parent, const GncGUID * guid)
{
GNCPrice *price;
- QofSession *session;
+ QofSession *session = gnc_get_current_session();
+ QofBook* book = qof_session_get_book (session);
- session = gnc_get_current_session ();
- price = gnc_price_lookup (guid, qof_session_get_book(session));
+ if (!book)
+ return (NULL);
+ price = gnc_price_lookup (guid, book);
if (price == NULL)
return(NULL);
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index 398d0224a..c7ab6d0b2 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -1816,6 +1816,11 @@ gnc_plugin_page_register_recreate_page (GtkWidget* window,
include_subs = (g_ascii_strcasecmp (reg_type, LABEL_SUBACCOUNT) == 0);
DEBUG ("Include subs: %d", include_subs);
book = qof_session_get_book (gnc_get_current_session());
+ if (book)
+ {
+ LEAVE("Session has no book");
+ return NULL;
+ }
acct_guid = g_key_file_get_string (key_file, group_name,
KEY_ACCOUNT_GUID, &error);
if (string_to_guid (acct_guid, &guid)) //find account by guid
diff --git a/gnucash/gnome/gnc-plugin-page-register2.c b/gnucash/gnome/gnc-plugin-page-register2.c
index 793a85635..1e8368c47 100644
--- a/gnucash/gnome/gnc-plugin-page-register2.c
+++ b/gnucash/gnome/gnc-plugin-page-register2.c
@@ -1495,6 +1495,11 @@ gnc_plugin_page_register2_recreate_page (GtkWidget *window,
acct_name = g_key_file_get_string (key_file, group_name,
KEY_ACCOUNT_NAME, &error);
book = qof_session_get_book (gnc_get_current_session());
+ if (book)
+ {
+ LEAVE("Session has no book");
+ return NULL;
+ }
account = gnc_account_lookup_by_full_name (gnc_book_get_root_account(book),
acct_name);
g_free (acct_name);
diff --git a/gnucash/gnome/top-level.c b/gnucash/gnome/top-level.c
index 0462c063e..eda1eee71 100644
--- a/gnucash/gnome/top-level.c
+++ b/gnucash/gnome/top-level.c
@@ -359,6 +359,11 @@ gnc_save_all_state (gpointer session, gpointer unused)
/* Store the book's GncGUID in the top level group */
book = qof_session_get_book(session);
+ if (!book)
+ {
+ PERR("Session has no book!");
+ return;
+ }
guid = qof_entity_get_guid(QOF_INSTANCE(book));
guid_to_string_buff(guid, guid_string);
g_key_file_set_string(keyfile, STATE_FILE_TOP, STATE_FILE_BOOK_GUID,
diff --git a/libgnucash/engine/engine-helpers.c b/libgnucash/engine/engine-helpers.c
index e92f55459..f6ac9aeb7 100644
--- a/libgnucash/engine/engine-helpers.c
+++ b/libgnucash/engine/engine-helpers.c
@@ -55,16 +55,19 @@ static QofLogModule log_module = GNC_MOD_ENGINE;
const char *
gnc_get_num_action (const Transaction *trans, const Split *split)
{
- gboolean num_action = qof_book_use_split_action_for_num_field
- (qof_session_get_book(gnc_get_current_session ()));
-
if (trans && !split)
return xaccTransGetNum(trans);
if (split && !trans)
return xaccSplitGetAction(split);
if (trans && split)
{
- if (num_action)
+ QofBook* book = qof_session_get_book(gnc_get_current_session ());
+ if (!book)
+ {
+ PERR("Session has no book but has a transaction or split!");
+ return NULL;
+ }
+ if (qof_book_use_split_action_for_num_field (book))
return xaccSplitGetAction(split);
else
return xaccTransGetNum(trans);
diff --git a/libgnucash/engine/qofbook.cpp b/libgnucash/engine/qofbook.cpp
index 0042778ad..34c170b8f 100644
--- a/libgnucash/engine/qofbook.cpp
+++ b/libgnucash/engine/qofbook.cpp
@@ -509,6 +509,7 @@ qof_book_get_session_dirty_time (const QofBook *book)
void
qof_book_set_dirty_cb(QofBook *book, QofBookDirtyCB cb, gpointer user_data)
{
+ g_return_if_fail(book);
if (book->dirty_cb)
PWARN("Already existing callback %p, will be overwritten by %p\n",
book->dirty_cb, cb);
@@ -1045,7 +1046,7 @@ qof_book_use_trading_accounts (const QofBook *book)
gboolean
qof_book_use_split_action_for_num_field (const QofBook *book)
{
- g_assert(book);
+ g_return_val_if_fail (book, FALSE);
if (!book->cached_num_field_source_isvalid)
{
// No cached value? Then do the expensive KVP lookup
Summary of changes:
gnucash/gnome-utils/gnc-tree-view-account.c | 2 ++
gnucash/gnome/dialog-invoice.c | 6 ++++++
gnucash/gnome/dialog-price-editor.c | 8 +++++---
gnucash/gnome/gnc-plugin-page-register.c | 5 +++++
gnucash/gnome/gnc-plugin-page-register2.c | 5 +++++
gnucash/gnome/top-level.c | 5 +++++
libgnucash/engine/engine-helpers.c | 11 +++++++----
libgnucash/engine/qofbook.cpp | 3 ++-
8 files changed, 37 insertions(+), 8 deletions(-)
More information about the gnucash-changes
mailing list