diff options
author | Richard Hughes <richard@hughsie.com> | 2009-03-19 11:51:50 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2009-03-19 11:51:50 +0000 |
commit | ed13111668cdeabffeb0357a5ded8fae110fbe3a (patch) | |
tree | 3718cca64b53ab7879dc1ab6858c7e921ef36b62 | |
parent | 23d3397b5bde78d852eb0237e370c68435069021 (diff) |
bugfix: fix compile error in dkp-power. Fixes #20749
-rw-r--r-- | src/dkp-history.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/dkp-history.c b/src/dkp-history.c index 8df3915..175bd38 100644 --- a/src/dkp-history.c +++ b/src/dkp-history.c @@ -119,7 +119,7 @@ dkp_history_array_limit_resolution (GPtrArray *array, guint max_num) DkpDeviceState state = DKP_DEVICE_STATE_UNKNOWN; guint64 time = 0; gdouble value = 0; - guint64 count; + guint64 count = 0; guint step = 1; gfloat preset; @@ -128,6 +128,8 @@ dkp_history_array_limit_resolution (GPtrArray *array, guint max_num) /* check length */ length = array->len; + if (length == 0) + goto out; if (length < max_num) { /* need to copy array */ g_ptr_array_foreach (array, (GFunc) dkp_history_array_copy_cb, new); @@ -170,11 +172,14 @@ dkp_history_array_limit_resolution (GPtrArray *array, guint max_num) } } - nobj = dkp_history_obj_new (); - nobj->time = time / count; - nobj->value = value / count; - nobj->state = state; - g_ptr_array_add (new, nobj); + /* only add if nonzero */ + if (count > 0) { + nobj = dkp_history_obj_new (); + nobj->time = time / count; + nobj->value = value / count; + nobj->state = state; + g_ptr_array_add (new, nobj); + } /* check length */ egg_debug ("length of array (after) %i", new->len); |