[Xfce4-commits] <xfce4-weather-plugin:master> Protect against some possible crashes.
Harald Judt
noreply at xfce.org
Sun Dec 9 23:44:08 CET 2012
Updating branch refs/heads/master
to cc9db7bb5fa11519433f5ab351a27c305ef1cdf3 (commit)
from ffecf234ed36e75113e7c0073d07ddfb74ece837 (commit)
commit cc9db7bb5fa11519433f5ab351a27c305ef1cdf3
Author: Harald Judt <h.judt at gmx.at>
Date: Sun Dec 9 19:24:20 2012 +0100
Protect against some possible crashes.
panel-plugin/weather-data.c | 11 ++++++-----
panel-plugin/weather-debug.c | 6 ++++++
panel-plugin/weather-icon.c | 2 +-
panel-plugin/weather.c | 8 ++++----
4 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c
index 4cc84b9..101274d 100644
--- a/panel-plugin/weather-data.c
+++ b/panel-plugin/weather-data.c
@@ -520,9 +520,7 @@ make_combined_timeslice(xml_weather *wd,
xml_time *
get_current_conditions(const xml_weather *wd)
{
- if (wd == NULL)
- return NULL;
- return wd->current_conditions;
+ return wd ? wd->current_conditions : NULL;
}
@@ -670,8 +668,11 @@ make_current_conditions(xml_weather *wd,
struct tm now_tm, start_tm, end_tm;
time_t end_t;
- /* now search for the nearest and shortest interval data
- available, using a maximum interval of 6 hours */
+ if (G_UNLIKELY(wd == NULL))
+ return NULL;
+
+ /* search for the nearest and shortest interval data available,
+ using a maximum interval of 6 hours */
now_tm = *localtime(&now_t);
end_tm = start_tm = now_tm;
diff --git a/panel-plugin/weather-debug.c b/panel-plugin/weather-debug.c
index a950199..cf211c1 100644
--- a/panel-plugin/weather-debug.c
+++ b/panel-plugin/weather-debug.c
@@ -348,6 +348,12 @@ weather_dump_weatherdata(const xml_weather *wd)
gboolean is_interval;
guint i;
+ if (G_UNLIKELY(wd == NULL))
+ return g_strdup("No weather data.");
+
+ if (G_UNLIKELY(wd->timeslices == NULL))
+ return g_strdup("Weather data: No timeslices available.");
+
out = g_string_sized_new(20480);
g_string_assign(out, "Timeslices (local time): ");
g_string_append_printf(out, "%d timeslices available.\n",
diff --git a/panel-plugin/weather-icon.c b/panel-plugin/weather-icon.c
index bf3ff61..6422e12 100644
--- a/panel-plugin/weather-icon.c
+++ b/panel-plugin/weather-icon.c
@@ -227,7 +227,7 @@ find_themes_in_dir(const gchar *path)
weather_debug("Looking for icon themes in %s.", path);
dir = g_dir_open(path, 0, NULL);
if (dir) {
- themes = g_array_new(FALSE, TRUE, sizeof(icon_theme*));
+ themes = g_array_new(FALSE, TRUE, sizeof(icon_theme *));
while (dirname = g_dir_read_name(dir)) {
themedir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 29b7fb8..afe8796 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -217,7 +217,6 @@ scrollbox_set_visible(xfceweather_data *data)
void
update_scrollbox(xfceweather_data *data)
{
- xml_time *conditions;
GString *out;
gchar *single = NULL;
data_types type;
@@ -227,7 +226,7 @@ update_scrollbox(xfceweather_data *data)
gtk_scrollbox_set_animate(GTK_SCROLLBOX(data->scrollbox),
data->scrollbox_animate);
- if (data->weatherdata) {
+ if (data->weatherdata && data->weatherdata->current_conditions) {
while (i < data->labels->len) {
j = 0;
out = g_string_sized_new(128);
@@ -241,7 +240,8 @@ update_scrollbox(xfceweather_data *data)
g_free(single);
j++;
}
- gtk_scrollbox_set_label(GTK_SCROLLBOX(data->scrollbox), -1, out->str);
+ gtk_scrollbox_set_label(GTK_SCROLLBOX(data->scrollbox),
+ -1, out->str);
g_string_free(out, TRUE);
i = i + j;
}
@@ -1030,7 +1030,7 @@ xfceweather_create_control(XfcePanelPlugin *plugin)
/* Initialize with sane default values */
data->plugin = plugin;
data->units = g_slice_new0(units_config);
- data->weatherdata = NULL;
+ data->weatherdata = g_slice_new0(xml_weather);
data->show_scrollbox = TRUE;
data->scrollbox_lines = 1;
data->scrollbox_animate = TRUE;
More information about the Xfce4-commits
mailing list