gnumeric r16662 - in trunk: . plugins/fn-stat
- From: mortenw svn gnome org
- To: svn-commits-list gnome org
- Subject: gnumeric r16662 - in trunk: . plugins/fn-stat
- Date: Tue, 24 Jun 2008 18:52:44 +0000 (UTC)
Author: mortenw
Date: Tue Jun 24 18:52:44 2008
New Revision: 16662
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16662&view=rev
Log:
2008-06-24 Morten Welinder <terra gnome org>
* functions.c (gnumeric_rank): Fix crash and error handling.
Fixes #540015.
Modified:
trunk/NEWS
trunk/plugins/fn-stat/ChangeLog
trunk/plugins/fn-stat/functions.c
Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS (original)
+++ trunk/NEWS Tue Jun 24 18:52:44 2008
@@ -52,6 +52,7 @@
* Plug leak in NETWORKDAYS.
* Add missing "return" in CODE.
* Fix EDATE issue. [#539868]
+ * Fix RANK crash. [#540015]
SeÃn de BÃrca:
* Move to tango based icons. [#450444]
Modified: trunk/plugins/fn-stat/functions.c
==============================================================================
--- trunk/plugins/fn-stat/functions.c (original)
+++ trunk/plugins/fn-stat/functions.c Tue Jun 24 18:52:44 2008
@@ -225,66 +225,33 @@
{ GNM_FUNC_HELP_END }
};
-typedef struct {
- gnm_float x;
- int order;
- int rank;
-} stat_rank_t;
-
static GnmValue *
-cb_rank (GnmCellIter const *iter, gpointer user)
+gnumeric_rank (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
- stat_rank_t *p = user;
- GnmCell *cell = iter->cell;
- gnm_float x;
+ gnm_float *xs;
+ int i, r, n;
+ GnmValue *result = NULL;
+ gnm_float x, order;
- gnm_cell_eval (cell);
- if (cell->value == NULL)
- return NULL;
+ x = value_get_as_float (argv[0]);
+ xs = collect_floats_value (argv[1], ei->pos,
+ COLLECT_IGNORE_STRINGS |
+ COLLECT_IGNORE_BOOLS |
+ COLLECT_IGNORE_BLANKS,
+ &n, &result);
+ order = argv[2] ? value_get_as_int (argv[2]) : 0;
- if (!VALUE_IS_NUMBER (cell->value))
- return NULL;
- /* FIXME: errors? bools? */
+ if (result)
+ return result;
- x = value_get_as_float (cell->value);
+ for (i = 0, r = 1; i < n; i++) {
+ gnm_float y = xs[i];
- if (p->order) {
- if (x < p->x)
- p->rank++;
- } else {
- if (x > p->x)
- p->rank++;
+ if (order ? y < x : y > x)
+ r++;
}
- return NULL;
-}
-
-static GnmValue *
-gnumeric_rank (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
-{
- stat_rank_t p;
- GnmValue *ret;
-
- p.x = value_get_as_float (argv[0]);
- if (argv[2])
- p.order = value_get_as_int (argv[2]);
- else
- p.order = 0;
- p.rank = 1;
- ret = sheet_foreach_cell_in_range (
- eval_sheet (argv[1]->v_range.cell.a.sheet, ei->pos->sheet),
- CELL_ITER_IGNORE_BLANK,
- argv[1]->v_range.cell.a.col,
- argv[1]->v_range.cell.a.row,
- argv[1]->v_range.cell.b.col,
- argv[1]->v_range.cell.b.row,
- cb_rank,
- &p);
-
- if (ret != NULL)
- return value_new_error_VALUE (ei->pos);
-
- return value_new_int (p.rank);
+ return value_new_int (r);
}
/***************************************************************************/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]