Skip to content

Commit

Permalink
Bug 797853 - Crash on 'Save As' in MacOS Mojave and Gnucash 4
Browse files Browse the repository at this point in the history
Check and handle null books throughout GnuCash. Tests are left alone
because they should fail if there's no book.
  • Loading branch information
jralls committed Jul 10, 2020
1 parent 1f95d3a commit edd7efd
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 8 deletions.
2 changes: 2 additions & 0 deletions gnucash/gnome-utils/gnc-tree-view-account.c
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions gnucash/gnome/dialog-invoice.c
Expand Up @@ -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)
{
Expand Down
8 changes: 5 additions & 3 deletions gnucash/gnome/dialog-price-editor.c
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions gnucash/gnome/gnc-plugin-page-register.c
Expand Up @@ -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)

This comment has been minimized.

Copy link
@christopherlam

christopherlam Jul 11, 2020

Contributor

typo? book -> !book ditto gnc-plugin-page-register2.c

This comment has been minimized.

Copy link
@jralls

jralls Jul 11, 2020

Author Member

Good catch. Thanks for fixing it.

{
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
Expand Down
5 changes: 5 additions & 0 deletions gnucash/gnome/gnc-plugin-page-register2.c
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions gnucash/gnome/top-level.c
Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions libgnucash/engine/engine-helpers.c
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion libgnucash/engine/qofbook.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit edd7efd

Please sign in to comment.