mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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.
This commit is contained in:
parent
1f95d3a711
commit
edd7efd951
@ -2507,6 +2507,7 @@ tree_restore_expanded_row (GncTreeViewAccount *view,
|
|||||||
QofBook *book;
|
QofBook *book;
|
||||||
|
|
||||||
book = qof_session_get_book(gnc_get_current_session());
|
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 = gnc_account_lookup_by_full_name(gnc_book_get_root_account(book),
|
||||||
account_name);
|
account_name);
|
||||||
if (account)
|
if (account)
|
||||||
@ -2529,6 +2530,7 @@ tree_restore_selected_row (GncTreeViewAccount *view,
|
|||||||
QofBook *book;
|
QofBook *book;
|
||||||
|
|
||||||
book = qof_session_get_book(gnc_get_current_session());
|
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 = gnc_account_lookup_by_full_name(gnc_book_get_root_account(book),
|
||||||
account_name);
|
account_name);
|
||||||
if (account)
|
if (account)
|
||||||
|
@ -3556,6 +3556,12 @@ gnc_invoice_show_docs_due (GtkWindow *parent, QofBook *book, double days_in_adva
|
|||||||
{ NULL },
|
{ NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!book)
|
||||||
|
{
|
||||||
|
PERR("No book, no due invoices.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Create the param list (in reverse order) */
|
/* Create the param list (in reverse order) */
|
||||||
if (param_list == NULL)
|
if (param_list == NULL)
|
||||||
{
|
{
|
||||||
|
@ -653,10 +653,12 @@ GNCPrice *
|
|||||||
gnc_price_edit_by_guid (GtkWidget * parent, const GncGUID * guid)
|
gnc_price_edit_by_guid (GtkWidget * parent, const GncGUID * guid)
|
||||||
{
|
{
|
||||||
GNCPrice *price;
|
GNCPrice *price;
|
||||||
QofSession *session;
|
QofSession *session = gnc_get_current_session();
|
||||||
|
QofBook* book = qof_session_get_book (session);
|
||||||
|
|
||||||
session = gnc_get_current_session ();
|
if (!book)
|
||||||
price = gnc_price_lookup (guid, qof_session_get_book(session));
|
return (NULL);
|
||||||
|
price = gnc_price_lookup (guid, book);
|
||||||
if (price == NULL)
|
if (price == NULL)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
|
||||||
|
@ -1816,6 +1816,11 @@ gnc_plugin_page_register_recreate_page (GtkWidget* window,
|
|||||||
include_subs = (g_ascii_strcasecmp (reg_type, LABEL_SUBACCOUNT) == 0);
|
include_subs = (g_ascii_strcasecmp (reg_type, LABEL_SUBACCOUNT) == 0);
|
||||||
DEBUG ("Include subs: %d", include_subs);
|
DEBUG ("Include subs: %d", include_subs);
|
||||||
book = qof_session_get_book (gnc_get_current_session());
|
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,
|
acct_guid = g_key_file_get_string (key_file, group_name,
|
||||||
KEY_ACCOUNT_GUID, &error);
|
KEY_ACCOUNT_GUID, &error);
|
||||||
if (string_to_guid (acct_guid, &guid)) //find account by guid
|
if (string_to_guid (acct_guid, &guid)) //find account by guid
|
||||||
|
@ -1495,6 +1495,11 @@ gnc_plugin_page_register2_recreate_page (GtkWidget *window,
|
|||||||
acct_name = g_key_file_get_string (key_file, group_name,
|
acct_name = g_key_file_get_string (key_file, group_name,
|
||||||
KEY_ACCOUNT_NAME, &error);
|
KEY_ACCOUNT_NAME, &error);
|
||||||
book = qof_session_get_book (gnc_get_current_session());
|
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),
|
account = gnc_account_lookup_by_full_name (gnc_book_get_root_account(book),
|
||||||
acct_name);
|
acct_name);
|
||||||
g_free (acct_name);
|
g_free (acct_name);
|
||||||
|
@ -359,6 +359,11 @@ gnc_save_all_state (gpointer session, gpointer unused)
|
|||||||
|
|
||||||
/* Store the book's GncGUID in the top level group */
|
/* Store the book's GncGUID in the top level group */
|
||||||
book = qof_session_get_book(session);
|
book = qof_session_get_book(session);
|
||||||
|
if (!book)
|
||||||
|
{
|
||||||
|
PERR("Session has no book!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
guid = qof_entity_get_guid(QOF_INSTANCE(book));
|
guid = qof_entity_get_guid(QOF_INSTANCE(book));
|
||||||
guid_to_string_buff(guid, guid_string);
|
guid_to_string_buff(guid, guid_string);
|
||||||
g_key_file_set_string(keyfile, STATE_FILE_TOP, STATE_FILE_BOOK_GUID,
|
g_key_file_set_string(keyfile, STATE_FILE_TOP, STATE_FILE_BOOK_GUID,
|
||||||
|
@ -55,16 +55,19 @@ static QofLogModule log_module = GNC_MOD_ENGINE;
|
|||||||
const char *
|
const char *
|
||||||
gnc_get_num_action (const Transaction *trans, const Split *split)
|
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)
|
if (trans && !split)
|
||||||
return xaccTransGetNum(trans);
|
return xaccTransGetNum(trans);
|
||||||
if (split && !trans)
|
if (split && !trans)
|
||||||
return xaccSplitGetAction(split);
|
return xaccSplitGetAction(split);
|
||||||
if (trans && 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);
|
return xaccSplitGetAction(split);
|
||||||
else
|
else
|
||||||
return xaccTransGetNum(trans);
|
return xaccTransGetNum(trans);
|
||||||
|
@ -509,6 +509,7 @@ qof_book_get_session_dirty_time (const QofBook *book)
|
|||||||
void
|
void
|
||||||
qof_book_set_dirty_cb(QofBook *book, QofBookDirtyCB cb, gpointer user_data)
|
qof_book_set_dirty_cb(QofBook *book, QofBookDirtyCB cb, gpointer user_data)
|
||||||
{
|
{
|
||||||
|
g_return_if_fail(book);
|
||||||
if (book->dirty_cb)
|
if (book->dirty_cb)
|
||||||
PWARN("Already existing callback %p, will be overwritten by %p\n",
|
PWARN("Already existing callback %p, will be overwritten by %p\n",
|
||||||
book->dirty_cb, cb);
|
book->dirty_cb, cb);
|
||||||
@ -1045,7 +1046,7 @@ qof_book_use_trading_accounts (const QofBook *book)
|
|||||||
gboolean
|
gboolean
|
||||||
qof_book_use_split_action_for_num_field (const QofBook *book)
|
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)
|
if (!book->cached_num_field_source_isvalid)
|
||||||
{
|
{
|
||||||
// No cached value? Then do the expensive KVP lookup
|
// No cached value? Then do the expensive KVP lookup
|
||||||
|
Loading…
Reference in New Issue
Block a user