From 5b7dbc3f41d5fe6dffba7e80cd5a92fb7afd9a22 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Thu, 5 Feb 2009 12:52:53 +0000 Subject: bugfix: don't crash when we limit the resolution of a small dataset --- src/dkp-history.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/dkp-history.c b/src/dkp-history.c index 616300c..c18f29e 100644 --- a/src/dkp-history.c +++ b/src/dkp-history.c @@ -146,12 +146,18 @@ dkp_history_array_limit_resolution (EggObjList *array, guint max_num) guint step = 1; gfloat preset; + /* check length */ + length = array->len; + if (length < max_num) { + new = g_object_ref (array); + goto out; + } + new = dkp_history_new_stats_list (); nobj = dkp_history_obj_new (); egg_debug ("length of array (before) %i", array->len); /* last element */ - length = array->len; obj = (const DkpHistoryObj *) egg_obj_list_index (array, length-1); last = obj->time; obj = (const DkpHistoryObj *) egg_obj_list_index (array, 0); @@ -194,6 +200,7 @@ dkp_history_array_limit_resolution (EggObjList *array, guint max_num) /* check length */ egg_debug ("length of array (after) %i", new->len); dkp_history_obj_free (nobj); +out: return new; } -- cgit v1.2.3