From 3dd3a1a1f441e8c86060d58b31850d21901f954d Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sat, 22 Aug 1998 22:42:44 +0000 Subject: [PATCH] fix core dump git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1022 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/register/splitreg.c | 5 +++++ src/register/table-allgui.c | 27 ++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/register/splitreg.c b/src/register/splitreg.c index 9bc7bac2c2..9e6f21168e 100644 --- a/src/register/splitreg.c +++ b/src/register/splitreg.c @@ -636,6 +636,11 @@ xaccInitSplitRegister (SplitRegister *reg, int type) void xaccConfigSplitRegister (SplitRegister *reg, int newtype) { + if (!reg) return; + + /* before reconfiguring, clean up any messy state that may be lying about */ + xaccVerifyCursorPosition (reg->table, -1, -1); + reg->type = newtype; configLayout (reg); configCursors (reg); diff --git a/src/register/table-allgui.c b/src/register/table-allgui.c index 5825f91444..2c2d6d920b 100644 --- a/src/register/table-allgui.c +++ b/src/register/table-allgui.c @@ -576,14 +576,31 @@ void xaccVerifyCursorPosition (Table *table, int phys_row, int phys_col) { int virt_row, virt_col; + int do_commit = 0; - /* compute the virtual position */ - virt_row = table->locators[phys_row][phys_col]->virt_row; - virt_col = table->locators[phys_row][phys_col]->virt_col; + if (!table) return; - if ((virt_row != table->current_cursor_virt_row) || - (virt_col != table->current_cursor_virt_col)) { + /* Someone may be trying to intentionally invalidate the cursor, + * in which case the physical addresses could be out of bounds. + * For example, in order to unmap it in preparation for a reconfig. + * So, if the specified location is out of bounds, then + * the cursor MUST be moved. + */ + if ((0 > phys_row) || (0 > phys_col)) do_commit = 1; + if (phys_row >= table->num_phys_rows) do_commit = 1; + if (phys_col >= table->num_phys_cols) do_commit = 1; + + /* Hmm, phys position is valid. Check the virtual position. */ + if (!do_commit) { + virt_row = table->locators[phys_row][phys_col]->virt_row; + virt_col = table->locators[phys_row][phys_col]->virt_col; + + if ((virt_row != table->current_cursor_virt_row) || + (virt_col != table->current_cursor_virt_col)) do_commit = 1; + } + + if (do_commit) { /* before leaving the current virtual position, * commit any edits that have been accumulated * in the cursor */