[gnome-software/wip/rancell/reviews] trivial: Use a safer method accessing a GArray
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/rancell/reviews] trivial: Use a safer method accessing a GArray
- Date: Tue, 9 Feb 2016 23:23:13 +0000 (UTC)
commit cb7b2597a833c941fdd7e4eec86b7682c5002fe8
Author: Robert Ancell <robert ancell canonical com>
Date: Wed Feb 10 12:22:55 2016 +1300
trivial: Use a safer method accessing a GArray
src/gs-review-histogram.c | 18 ++++++++++--------
1 files changed, 10 insertions(+), 8 deletions(-)
---
diff --git a/src/gs-review-histogram.c b/src/gs-review-histogram.c
index 340982f..d98616a 100644
--- a/src/gs-review-histogram.c
+++ b/src/gs-review-histogram.c
@@ -61,20 +61,22 @@ gs_review_histogram_set_ratings (GsReviewHistogram *histogram,
{
GsReviewHistogramPrivate *priv;
gdouble max;
- gint count[5];
+ gint count[5] = { 0, 0, 0, 0, 0 };
guint i;
g_return_if_fail (GS_IS_REVIEW_HISTOGRAM (histogram));
priv = gs_review_histogram_get_instance_private (histogram);
/* Scale to maximum value */
- for (i = 0; i < 5; i++)
- count[i] = g_array_index (review_ratings, gint, i + 1);
- max = count[0];
- max = count[1] > max ? count[1] : max;
- max = count[2] > max ? count[2] : max;
- max = count[3] > max ? count[3] : max;
- max = count[4] > max ? count[4] : max;
+ for (max = 0, i = 0; i < review_ratings->len; i++) {
+ gint c;
+
+ c = g_array_index (review_ratings, gint, i);
+ if (c > max)
+ max = c;
+ if (i > 0 && i < 6)
+ count[i - 1] = c;
+ }
gs_review_bar_set_fraction (GS_REVIEW_BAR (priv->bar5), count[4] / max);
set_label (priv->label_count5, count[4]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]