diff --git a/widgets/table/e-table-sorting-utils.c b/widgets/table/e-table-sorting-utils.c
index 344a7cf..85b3117 100644
--- a/widgets/table/e-table-sorting-utils.c
+++ b/widgets/table/e-table-sorting-utils.c
@@ -134,7 +134,7 @@ e_table_sorting_utils_sort(ETableModel *source, ETableSortInfo *sort_info, ETabl
 		col = e_table_header_get_column_by_col_idx(full_header, column.column);
 		if (col == NULL)
 			col = e_table_header_get_column (full_header, e_table_header_count (full_header) - 1);
-		for (i = 0; i < rows; i++) {
+		for (i = 0; (closure.vals != NULL) && (i < rows); i++) {
 			closure.vals[map_table[i] * cols + j] = e_table_model_value_at (source, col->compare_col, map_table[i]);
 		}
 		closure.compare[j] = col->compare;
