gnucash maint: Ensure all uses of g_table_index are protected from NULL return values.
John Ralls
jralls at code.gnucash.org
Fri Nov 8 16:13:37 EST 2019
Updated via https://github.com/Gnucash/gnucash/commit/a4773d2b (commit)
from https://github.com/Gnucash/gnucash/commit/2bc7d314 (commit)
commit a4773d2ba7d05f973f44eb9be1af866576131150
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Nov 8 13:12:05 2019 -0800
Ensure all uses of g_table_index are protected from NULL return values.
Including all of the convenience wrappers.
Also remove a few calls where the result is discarded, as it has no
side effects.
diff --git a/gnucash/register/ledger-core/gncEntryLedgerControl.c b/gnucash/register/ledger-core/gncEntryLedgerControl.c
index b36e44d83..f1e19f812 100644
--- a/gnucash/register/ledger-core/gncEntryLedgerControl.c
+++ b/gnucash/register/ledger-core/gncEntryLedgerControl.c
@@ -234,7 +234,6 @@ static void gnc_entry_ledger_move_cursor (VirtualLocation *p_new_virt_loc,
* then it may have moved. Find out where it is now. */
if (gnc_entry_ledger_find_entry (ledger, new_entry, &vcell_loc))
{
- gnc_table_get_virtual_cell (ledger->table, vcell_loc);
new_virt_loc.vcell_loc = vcell_loc;
}
else
diff --git a/gnucash/register/ledger-core/split-register-control.c b/gnucash/register/ledger-core/split-register-control.c
index 57be98e7c..00cc42999 100644
--- a/gnucash/register/ledger-core/split-register-control.c
+++ b/gnucash/register/ledger-core/split-register-control.c
@@ -543,7 +543,6 @@ gnc_split_register_move_cursor (VirtualLocation *p_new_virt_loc,
new_split, new_class, &vcell_loc))
{
- gnc_table_get_virtual_cell (reg->table, vcell_loc);
new_virt_loc.vcell_loc = vcell_loc;
}
else
diff --git a/gnucash/register/register-gnome/gnucash-header.c b/gnucash/register/register-gnome/gnucash-header.c
index 1b2de66d7..e5aceae8a 100644
--- a/gnucash/register/register-gnome/gnucash-header.c
+++ b/gnucash/register/register-gnome/gnucash-header.c
@@ -350,8 +350,8 @@ find_resize_col (GncHeader *header, int col)
/* skip to the right over zero-width columns */
while ((col + 1 < style->ncols) &&
(cd = gnucash_style_get_cell_dimensions (style, 0, col + 1)) &&
- (cd->pixel_width == 0))
- col++;
+ cd && (cd->pixel_width == 0))
+ ++col;
/* now go back left till we have a resizable column */
while (col >= start)
diff --git a/gnucash/register/register-gnome/gnucash-sheet.c b/gnucash/register/register-gnome/gnucash-sheet.c
index 889e78077..fd5b8f6c5 100644
--- a/gnucash/register/register-gnome/gnucash-sheet.c
+++ b/gnucash/register/register-gnome/gnucash-sheet.c
@@ -564,7 +564,8 @@ gnucash_sheet_show_row (GnucashSheet *sheet, gint virt_row)
height = alloc.height;
block = gnucash_sheet_get_block (sheet, vcell_loc);
-
+ if (!block)
+ return;
y = block->origin_y;
block_height = block->style->dimensions->height;
@@ -644,6 +645,8 @@ gnucash_sheet_show_range (GnucashSheet *sheet,
start_block = gnucash_sheet_get_block (sheet, start_loc);
end_block = gnucash_sheet_get_block (sheet, end_loc);
+ if (!(start_block && end_block))
+ return;
y = start_block->origin_y;
block_height = (end_block->origin_y +
@@ -2228,7 +2231,7 @@ gnucash_sheet_block_set_from_table (GnucashSheet *sheet,
block = gnucash_sheet_get_block (sheet, vcell_loc);
style = gnucash_sheet_get_style_from_table (sheet, vcell_loc);
- if (block == NULL)
+ if (!block)
return FALSE;
table = sheet->table;
@@ -2275,6 +2278,9 @@ gnucash_sheet_col_max_width (GnucashSheet *sheet, gint virt_col, gint cell_col)
VirtualCellLocation vcell_loc = { virt_row, virt_col };
block = gnucash_sheet_get_block (sheet, vcell_loc);
+ if (!block)
+ continue;
+
style = block->style;
if (!style)
@@ -2410,6 +2416,9 @@ gnucash_sheet_recompute_block_offsets (GnucashSheet *sheet)
block = gnucash_sheet_get_block (sheet, vcell_loc);
+ if (!block)
+ continue;
+
block->origin_x = width;
block->origin_y = height;
diff --git a/gnucash/register/register-gnome/gnucash-style.c b/gnucash/register/register-gnome/gnucash-style.c
index 83ce8e4e8..13d801e4b 100644
--- a/gnucash/register/register-gnome/gnucash-style.c
+++ b/gnucash/register/register-gnome/gnucash-style.c
@@ -158,6 +158,10 @@ compute_row_width (BlockDimensions *dimensions, int row, int col1, int col2)
{
CellDimensions *cd;
cd = g_table_index (dimensions->cell_dimensions, row, j);
+
+ if (!cd)
+ continue;
+
width += cd->pixel_width;
}
@@ -190,7 +194,7 @@ set_dimensions_pass_one (GnucashSheet *sheet, CellBlock *cursor,
row, col);
cell = gnc_cellblock_get_cell (cursor, row, col);
- if (!cell)
+ if (!cell || !cd)
continue;
text = cell->sample_text;
@@ -228,7 +232,6 @@ set_dimensions_pass_one (GnucashSheet *sheet, CellBlock *cursor,
cd->pixel_width = MAX (cd->pixel_width, width);
}
- g_table_index (dimensions->cell_dimensions, row, 0);
dimensions->height += max_height;
}
@@ -238,6 +241,9 @@ set_dimensions_pass_one (GnucashSheet *sheet, CellBlock *cursor,
{
cd = g_table_index (dimensions->cell_dimensions,
row, col);
+ if (!cd)
+ continue;
+
cd->pixel_height = max_height;
}
}
@@ -277,6 +283,9 @@ set_dimensions_pass_two (GnucashSheet *sheet, int default_width)
{
cd = g_table_index (cd_table, 0, col);
+ if (!cd)
+ continue;
+
widths[col] = cd->pixel_width;
width += cd->pixel_width;
}
@@ -293,6 +302,9 @@ set_dimensions_pass_two (GnucashSheet *sheet, int default_width)
cd = g_table_index (cd_table, 0, col);
+ if (!cd)
+ continue;
+
cd->pixel_width += (default_width - width);
widths[col] = cd->pixel_width;
@@ -315,6 +327,9 @@ set_dimensions_pass_two (GnucashSheet *sheet, int default_width)
cd = g_table_index (cd_table, 0, col);
+ if (!cd)
+ continue;
+
cd->pixel_width += (default_width - width);
text = cell->sample_text;
@@ -354,6 +369,9 @@ set_dimensions_pass_two (GnucashSheet *sheet, int default_width)
{
cd = g_table_index (cd_table, row, col);
+ if (!cd)
+ continue;
+
cd->pixel_width = widths[col];
}
}
@@ -390,7 +408,7 @@ set_dimensions_pass_two (GnucashSheet *sheet, int default_width)
continue;
}
- if (!cd->can_span_over)
+ if (!cd || !cd->can_span_over)
continue;
if (cd_span == NULL)
@@ -440,6 +458,9 @@ compute_cell_origins_x (BlockDimensions *dimensions)
cd = g_table_index (dimensions->cell_dimensions, i, j);
+ if (!cd)
+ continue;
+
cd->origin_x = x;
x += cd->pixel_width;
}
@@ -458,9 +479,17 @@ compute_cell_origins_y (BlockDimensions *dimensions)
for (j = 0; j < dimensions->ncols; j++)
{
cd = g_table_index (dimensions->cell_dimensions, i, j);
+
+ if (!cd)
+ continue;
+
cd->origin_y = y;
}
cd = g_table_index (dimensions->cell_dimensions, i, 0);
+
+ if (!cd)
+ continue;
+
y += cd->pixel_height;
}
}
@@ -774,6 +803,9 @@ gnucash_sheet_get_style_from_table (GnucashSheet *sheet,
vcell = gnc_table_get_virtual_cell (table, vcell_loc);
+ if (!vcell)
+ return NULL;
+
cursor = vcell->cellblock;
style = gnucash_sheet_get_style_from_cursor (sheet,
Summary of changes:
.../register/ledger-core/gncEntryLedgerControl.c | 1 -
.../register/ledger-core/split-register-control.c | 1 -
gnucash/register/register-gnome/gnucash-header.c | 4 +--
gnucash/register/register-gnome/gnucash-sheet.c | 13 ++++++--
gnucash/register/register-gnome/gnucash-style.c | 38 ++++++++++++++++++++--
5 files changed, 48 insertions(+), 9 deletions(-)
More information about the gnucash-changes
mailing list