[gnumeric] SUMIF: fix problems with blank criteria.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] SUMIF: fix problems with blank criteria.
- Date: Thu, 31 Oct 2019 17:10:10 +0000 (UTC)
commit 96c476dbc60b880e8a71132e3413867758380ca0
Author: Morten Welinder <terra gnome org>
Date: Thu Oct 31 13:09:45 2019 -0400
SUMIF: fix problems with blank criteria.
ChangeLog | 6 ++++++
NEWS | 1 +
src/criteria.c | 30 ++++++++++++++++++++++++++++--
3 files changed, 35 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b4412130e..ec48b9156 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-10-31 Morten Welinder <terra gnome org>
+
+ * src/criteria.c (parse_criteria): Be careful about critiria that
+ are either empty values or empty strings. The semantics are
+ special. [#423] Fix initial ref-count problem.
+
2019-09-19 Jean Brefort <jean brefort normalesup org>
* src/cell-draw.c (cell_calc_layout): implement wrapping of rotated text.
diff --git a/NEWS b/NEWS
index 4716e9145..6530db1d0 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ Morten:
* Fix inter-process paste crash [#406]
* Fix problem saving cell protection to xlsx. [#409]
* Look for python3 before python. [#419]
+ * Fix SUMIF (etc) problem with blank criteria. [#423]
--------------------------------------------------------------------------
Gnumeric 1.12.45
diff --git a/src/criteria.c b/src/criteria.c
index 1e297b975..a41245440 100644
--- a/src/criteria.c
+++ b/src/criteria.c
@@ -203,12 +203,28 @@ criteria_test_empty (GnmValue const *x, GnmCriteria *crit)
return VALUE_IS_EMPTY (x);
}
+static gboolean
+criteria_test_blank (GnmValue const *x, GnmCriteria *crit)
+{
+ if (VALUE_IS_EMPTY (x))
+ return TRUE;
+ if (!VALUE_IS_STRING (x))
+ return FALSE;
+ return *value_peek_string (x) == 0;
+}
+
static gboolean
criteria_test_nonempty (GnmValue const *x, GnmCriteria *crit)
{
return !VALUE_IS_EMPTY (x);
}
+static gboolean
+criteria_test_nothing (GnmValue const *x, GnmCriteria *crit)
+{
+ return FALSE;
+}
+
/*
* Finds a column index of a field.
*/
@@ -345,6 +361,7 @@ parse_criteria (GnmValue const *crit_val, GODateConventions const *date_conv,
res->iter_flags = CELL_ITER_IGNORE_BLANK;
res->date_conv = date_conv;
+ res->ref_count = 1;
if (VALUE_IS_NUMBER (crit_val)) {
res->fun = criteria_test_equal;
@@ -352,8 +369,18 @@ parse_criteria (GnmValue const *crit_val, GODateConventions const *date_conv,
return res;
}
+ if (VALUE_IS_EMPTY (crit_val)) {
+ // Empty value
+ res->fun = criteria_test_nothing;
+ res->x = value_new_empty ();
+ return res;
+ }
+
criteria = value_peek_string (crit_val);
- if (strncmp (criteria, "<=", 2) == 0) {
+ if (*criteria == 0) {
+ res->fun = criteria_test_blank;
+ len = 0;
+ } else if (strncmp (criteria, "<=", 2) == 0) {
res->fun = criteria_test_less_or_equal;
len = 2;
} else if (strncmp (criteria, ">=", 2) == 0) {
@@ -389,7 +416,6 @@ parse_criteria (GnmValue const *crit_val, GODateConventions const *date_conv,
if (res->fun (empty, res))
res->iter_flags &= ~CELL_ITER_IGNORE_BLANK;
value_release (empty);
- res->ref_count = 1;
return res;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]