[Xfce4-commits] <xfce4-weather-plugin:master> Use guint only where it makes sense.

Harald Judt noreply at xfce.org
Mon Dec 10 19:58:04 CET 2012


Updating branch refs/heads/master
         to eea713ab3e38636da62a50d6e966d4a9adc0098e (commit)
       from 729c9a82c37670ac5b155340d6e8f9080b3456c2 (commit)

commit eea713ab3e38636da62a50d6e966d4a9adc0098e
Author: Harald Judt <h.judt at gmx.at>
Date:   Mon Dec 10 19:51:40 2012 +0100

    Use guint only where it makes sense.
    
    Especially for loop variables, if someone refactors code later and values
    get negative, then the effects can turn very negative ;-)

 panel-plugin/weather-config.c    |   11 +++++------
 panel-plugin/weather-data.c      |   14 +++++++-------
 panel-plugin/weather-debug.c     |    4 ++--
 panel-plugin/weather-parsers.c   |    6 +++---
 panel-plugin/weather-translate.c |    9 ++++-----
 panel-plugin/weather.c           |   15 +++++++--------
 panel-plugin/weather.h           |    2 +-
 7 files changed, 29 insertions(+), 32 deletions(-)

diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index 30aef60..523ad8b 100644
--- a/panel-plugin/weather-config.c
+++ b/panel-plugin/weather-config.c
@@ -844,7 +844,7 @@ create_appearance_page(xfceweather_dialog *dialog)
     GtkWidget *palign, *page, *sep, *hbox, *vbox, *label;
     GtkSizeGroup *sg;
     icon_theme *theme;
-    guint i;
+    gint i;
 
     ADD_PAGE(FALSE);
     sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
@@ -938,7 +938,7 @@ spin_scrollbox_lines_value_changed(const GtkWidget *spin,
 {
     xfceweather_dialog *dialog = (xfceweather_dialog *) user_data;
     dialog->pd->scrollbox_lines =
-        (guint) gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
+        gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
     update_scrollbox(dialog->pd);
 }
 
@@ -1034,7 +1034,7 @@ static GtkWidget *
 make_label(void)
 {
     GtkWidget *widget, *menu;
-    guint i;
+    gint i;
 
     menu = gtk_menu_new();
     widget = gtk_option_menu_new();
@@ -1092,7 +1092,7 @@ add_model_option(GtkListStore *model,
 static int
 option_i(const data_types opt)
 {
-    guint i;
+    gint i;
 
     for (i = 0; i < OPTIONS_N; i++)
         if (labeloptions[i].number == opt)
@@ -1205,8 +1205,7 @@ create_scrollbox_page(xfceweather_dialog *dialog)
     GtkTreeViewColumn *column;
     GtkCellRenderer *renderer;
     data_types type;
-    guint i;
-    gint n;
+    gint i, n;
 
     ADD_PAGE(FALSE);
     sg_misc = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c
index 02a8399..b93f6cd 100644
--- a/panel-plugin/weather-data.c
+++ b/panel-plugin/weather-data.c
@@ -417,7 +417,7 @@ make_combined_timeslice(xml_weather *wd,
 {
     xml_time *comb, *start, *end;
     gboolean ipol = (between_t != NULL) ? TRUE : FALSE;
-    guint i;
+    gint i;
 
     /* find point data at start of interval (may not be available) */
     start = get_timeslice(wd, interval->start, interval->start, NULL);
@@ -498,7 +498,7 @@ merge_timeslice(xml_weather *wd,
 {
     xml_time *old_ts, *new_ts;
     time_t now_t = time(NULL);
-    guint i;
+    guint index;
 
     g_assert(wd != NULL);
     if (G_UNLIKELY(wd == NULL))
@@ -515,12 +515,12 @@ merge_timeslice(xml_weather *wd,
 
     /* check if there is a timeslice with the same interval and
        replace it with the current data */
-    old_ts = get_timeslice(wd, timeslice->start, timeslice->end, &i);
+    old_ts = get_timeslice(wd, timeslice->start, timeslice->end, &index);
     if (old_ts) {
         xml_time_free(old_ts);
-        g_array_remove_index(wd->timeslices, i);
-        g_array_insert_val(wd->timeslices, i, new_ts);
-        weather_debug("Replaced existing timeslice at %d.", i);
+        g_array_remove_index(wd->timeslices, index);
+        g_array_insert_val(wd->timeslices, index, new_ts);
+        weather_debug("Replaced existing timeslice at %d.", index);
     } else {
         g_array_prepend_val(wd->timeslices, new_ts);
         //weather_debug("Prepended timeslice to the existing timeslices.");
@@ -700,8 +700,8 @@ find_point_data(const xml_weather *wd,
 {
     point_data_results *found;
     xml_time *timeslice;
-    guint i;
     gdouble diff;
+    gint i;
 
     found = g_slice_new0(point_data_results);
     found->before = g_array_new(FALSE, TRUE, sizeof(xml_time *));
diff --git a/panel-plugin/weather-debug.c b/panel-plugin/weather-debug.c
index e3bc0b6..2e85acd 100644
--- a/panel-plugin/weather-debug.c
+++ b/panel-plugin/weather-debug.c
@@ -56,7 +56,7 @@ weather_debug_init(const gchar *log_domain,
     const gchar *debug_env;
     gchar *debug_env_new_array[] = { NULL, NULL, NULL, NULL };
     gchar *debug_env_new;
-    guint i = 0, j = 0;
+    gint i = 0, j = 0;
 
     if (debug_mode) {
         debug_env = g_getenv("G_MESSAGES_DEBUG");
@@ -373,7 +373,7 @@ weather_dump_weatherdata(const xml_weather *wd)
     GString *out;
     xml_time *timeslice;
     gchar *result, *tmp;
-    guint i;
+    gint i;
 
     if (G_UNLIKELY(wd == NULL))
         return g_strdup("No weather data.");
diff --git a/panel-plugin/weather-parsers.c b/panel-plugin/weather-parsers.c
index 89b09d5..93124cc 100644
--- a/panel-plugin/weather-parsers.c
+++ b/panel-plugin/weather-parsers.c
@@ -78,7 +78,7 @@ get_timeslice(xml_weather *wd,
               guint *index)
 {
     xml_time *timeslice;
-    guint i;
+    gint i;
 
     g_assert(wd != NULL);
     if (G_UNLIKELY(wd == NULL))
@@ -677,7 +677,7 @@ void
 xml_weather_free(xml_weather *wd)
 {
     xml_time *timeslice;
-    guint i;
+    gint i;
 
     g_assert(wd != NULL);
     if (G_UNLIKELY(wd == NULL))
@@ -703,7 +703,7 @@ xml_weather_clean(xml_weather *wd)
 {
     xml_time *timeslice;
     time_t now_t = time(NULL);
-    guint i;
+    gint i;
 
     if (G_UNLIKELY(wd == NULL || wd->timeslices == NULL))
         return;
diff --git a/panel-plugin/weather-translate.c b/panel-plugin/weather-translate.c
index aae4c7b..8dcdd66 100644
--- a/panel-plugin/weather-translate.c
+++ b/panel-plugin/weather-translate.c
@@ -71,8 +71,7 @@ static const gchar *
 translate_str(const gchar **loc_strings,
               const gchar *str)
 {
-    gint loc_string_len, str_len;
-    guint i;
+    gint loc_string_len, str_len, i;
 
     if (str == NULL)
         return "?";
@@ -187,7 +186,7 @@ const gchar *
 translate_desc(const gchar *desc,
                const gboolean nighttime)
 {
-    guint i;
+    gint i;
 
     for (i = 0; i < NUM_SYMBOLS; i++)
         if (!strcmp(desc, symbol_to_desc[i].symbol))
@@ -202,7 +201,7 @@ translate_desc(const gchar *desc,
 const gchar *
 translate_moon_phase(const gchar *moon_phase)
 {
-    guint i;
+    gint i;
 
     for (i = 0; i < NUM_MOON_PHASES; i++)
         if (!strcmp(moon_phase, moon_phases[i]))
@@ -241,7 +240,7 @@ gchar *
 translate_wind_direction(const gchar *wdir)
 {
     gchar *wdir_loc, *tmp, wdir_i[2];
-    guint i;
+    gint i;
 
     if (wdir == NULL || strlen(wdir) < 1)
         return NULL;
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index aef99f5..ca422c1 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -239,7 +239,7 @@ update_scrollbox(plugin_data *data)
     GString *out;
     gchar *single = NULL;
     data_types type;
-    guint i = 0, j = 0;
+    gint i = 0, j = 0;
 
     gtk_scrollbox_clear(GTK_SCROLLBOX(data->scrollbox));
     gtk_scrollbox_set_animate(GTK_SCROLLBOX(data->scrollbox),
@@ -534,8 +534,7 @@ xfceweather_read_config(XfcePanelPlugin *plugin,
     const gchar *value;
     gchar *file;
     gchar label[10];
-    guint label_count = 0;
-    gint val;
+    gint label_count = 0, val;
 
     if (!(file = xfce_panel_plugin_lookup_rc_file(plugin)))
         return;
@@ -655,10 +654,10 @@ static void
 xfceweather_write_config(XfcePanelPlugin *plugin,
                          plugin_data *data)
 {
-    gchar label[10];
-    guint i;
     XfceRc *rc;
+    gchar label[10];
     gchar *file, *value;
+    gint i;
 
     if (!(file = xfce_panel_plugin_save_location(plugin, TRUE)))
         return;
@@ -781,7 +780,7 @@ write_cache_file(plugin_data *data)
     xml_location *loc;
     gchar *file, *start, *end, *point, *now;
     time_t now_t = time(NULL);
-    guint i, j;
+    gint i, j;
 
     file = make_cache_filename(data);
     if (G_UNLIKELY(file == NULL))
@@ -1105,7 +1104,7 @@ xfceweather_dialog_response(GtkWidget *dlg,
     plugin_data *data = (plugin_data *) dialog->pd;
     icon_theme *theme;
     gboolean result;
-    guint i;
+    gint i;
 
     if (response == GTK_RESPONSE_HELP) {
         /* show help */
@@ -1307,7 +1306,7 @@ weather_get_tooltip_cb(GtkWidget *widget,
     GdkPixbuf *icon;
     xml_time *conditions;
     gchar *markup_text, *rawvalue;
-    guint icon_size;
+    gint icon_size;
 
     if (data->weatherdata == NULL)
         gtk_tooltip_set_text(tooltip, _("Cannot update weather data"));
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index 3a1d8a2..e2541e5 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -75,7 +75,7 @@ typedef struct {
 
     GtkWidget *scrollbox;
     gboolean show_scrollbox;
-    guint scrollbox_lines;
+    gint scrollbox_lines;
     gchar *scrollbox_font;
     GdkColor scrollbox_color;
     gboolean scrollbox_use_color;


More information about the Xfce4-commits mailing list