libgweather r525 - in trunk: . libgweather
- From: vuntz svn gnome org
- To: svn-commits-list gnome org
- Subject: libgweather r525 - in trunk: . libgweather
- Date: Wed, 26 Nov 2008 00:13:06 +0000 (UTC)
Author: vuntz
Date: Wed Nov 26 00:13:06 2008
New Revision: 525
URL: http://svn.gnome.org/viewvc/libgweather?rev=525&view=rev
Log:
2008-11-26 Vincent Untz <vuntz gnome org>
* libgweather/gweather-gconf.c:
* libgweather/gweather-location.c:
* libgweather/gweather-prefs.c:
* libgweather/gweather-timezone.c:
* libgweather/timezone-menu.c:
* libgweather/weather-sun.c:
* libgweather/weather.c:
Add some safety guards with g_return[_val]_if_fail() to public API.
Hopefully, I did it right. I guess people will notice quickly if it's
not the case ;-)
Modified:
trunk/ChangeLog
trunk/libgweather/gweather-gconf.c
trunk/libgweather/gweather-location.c
trunk/libgweather/gweather-prefs.c
trunk/libgweather/gweather-timezone.c
trunk/libgweather/timezone-menu.c
trunk/libgweather/weather-sun.c
trunk/libgweather/weather.c
Modified: trunk/libgweather/gweather-gconf.c
==============================================================================
--- trunk/libgweather/gweather-gconf.c (original)
+++ trunk/libgweather/gweather-gconf.c Wed Nov 26 00:13:06 2008
@@ -54,6 +54,9 @@
void
gweather_gconf_free (GWeatherGConf *ctx)
{
+ if (!ctx)
+ return;
+
g_object_unref (ctx->gconf);
g_free (ctx->prefix);
g_free (ctx);
@@ -63,6 +66,7 @@
GConfClient *
gweather_gconf_get_client (GWeatherGConf *ctx)
{
+ g_return_val_if_fail (ctx != NULL, NULL);
return ctx->gconf;
}
@@ -71,6 +75,9 @@
gweather_gconf_get_full_key (GWeatherGConf *ctx,
const gchar *key)
{
+ g_return_val_if_fail (ctx != NULL, NULL);
+ g_return_val_if_fail (key != NULL, NULL);
+
return g_strdup_printf ("%s/%s", ctx->prefix, key);
}
@@ -80,7 +87,13 @@
gboolean the_bool,
GError **opt_error)
{
- gchar *full_key = gweather_gconf_get_full_key (ctx, key);
+ gchar *full_key;
+
+ g_return_if_fail (ctx != NULL);
+ g_return_if_fail (key != NULL);
+ g_return_if_fail (opt_error == NULL || *opt_error == NULL);
+
+ full_key = gweather_gconf_get_full_key (ctx, key);
gconf_client_set_bool (ctx->gconf, full_key, the_bool, opt_error);
g_free (full_key);
}
@@ -91,7 +104,13 @@
gint the_int,
GError **opt_error)
{
- gchar *full_key = gweather_gconf_get_full_key (ctx, key);
+ gchar *full_key;
+
+ g_return_if_fail (ctx != NULL);
+ g_return_if_fail (key != NULL);
+ g_return_if_fail (opt_error == NULL || *opt_error == NULL);
+
+ full_key = gweather_gconf_get_full_key (ctx, key);
gconf_client_set_int (ctx->gconf, full_key, the_int, opt_error);
g_free (full_key);
}
@@ -102,7 +121,13 @@
const gchar *the_string,
GError **opt_error)
{
- gchar *full_key = gweather_gconf_get_full_key (ctx, key);
+ gchar *full_key;
+
+ g_return_if_fail (ctx != NULL);
+ g_return_if_fail (key != NULL);
+ g_return_if_fail (opt_error == NULL || *opt_error == NULL);
+
+ full_key = gweather_gconf_get_full_key (ctx, key);
gconf_client_set_string (ctx->gconf, full_key, the_string, opt_error);
g_free (full_key);
}
@@ -112,8 +137,15 @@
const gchar *key,
GError **opt_error)
{
- gchar *full_key = gweather_gconf_get_full_key (ctx, key);
- gboolean ret = gconf_client_get_bool (ctx->gconf, full_key, opt_error);
+ gchar *full_key;
+ gboolean ret;
+
+ g_return_val_if_fail (ctx != NULL, FALSE);
+ g_return_val_if_fail (key != NULL, FALSE);
+ g_return_val_if_fail (opt_error == NULL || *opt_error == NULL, FALSE);
+
+ full_key = gweather_gconf_get_full_key (ctx, key);
+ ret = gconf_client_get_bool (ctx->gconf, full_key, opt_error);
g_free (full_key);
return ret;
}
@@ -123,8 +155,15 @@
const gchar *key,
GError **opt_error)
{
- gchar *full_key = gweather_gconf_get_full_key (ctx, key);
- gint ret = gconf_client_get_int (ctx->gconf, full_key, opt_error);
+ gchar *full_key;
+ gint ret;
+
+ g_return_val_if_fail (ctx != NULL, 0);
+ g_return_val_if_fail (key != NULL, 0);
+ g_return_val_if_fail (opt_error == NULL || *opt_error == NULL, 0);
+
+ full_key = gweather_gconf_get_full_key (ctx, key);
+ ret = gconf_client_get_int (ctx->gconf, full_key, opt_error);
g_free (full_key);
return ret;
}
@@ -134,8 +173,15 @@
const gchar *key,
GError **opt_error)
{
- gchar *full_key = gweather_gconf_get_full_key (ctx, key);
- gchar *ret = gconf_client_get_string (ctx->gconf, full_key, opt_error);
+ gchar *full_key;
+ gchar *ret;
+
+ g_return_val_if_fail (ctx != NULL, NULL);
+ g_return_val_if_fail (key != NULL, NULL);
+ g_return_val_if_fail (opt_error == NULL || *opt_error == NULL, NULL);
+
+ full_key = gweather_gconf_get_full_key (ctx, key);
+ ret = gconf_client_get_string (ctx->gconf, full_key, opt_error);
g_free (full_key);
return ret;
}
@@ -147,6 +193,8 @@
WeatherLocation *location;
gchar *name, *code, *zone, *radar, *coordinates;
+ g_return_val_if_fail (ctx != NULL, NULL);
+
name = gweather_gconf_get_string (ctx, "location4", NULL);
if (!name)
{
Modified: trunk/libgweather/gweather-location.c
==============================================================================
--- trunk/libgweather/gweather-location.c (original)
+++ trunk/libgweather/gweather-location.c Wed Nov 26 00:13:06 2008
@@ -284,6 +284,8 @@
GWeatherLocation *
gweather_location_ref (GWeatherLocation *loc)
{
+ g_return_val_if_fail (loc != NULL, NULL);
+
loc->ref_count++;
return loc;
}
@@ -293,6 +295,8 @@
{
int i;
+ g_return_if_fail (loc != NULL);
+
if (--loc->ref_count)
return;
@@ -339,30 +343,36 @@
const char *
gweather_location_get_name (GWeatherLocation *loc)
{
+ g_return_val_if_fail (loc != NULL, NULL);
return loc->name;
}
const char *
gweather_location_get_sort_name (GWeatherLocation *loc)
{
+ g_return_val_if_fail (loc != NULL, NULL);
return loc->sort_name;
}
GWeatherLocationLevel
gweather_location_get_level (GWeatherLocation *loc)
{
+ g_return_val_if_fail (loc != NULL, GWEATHER_LOCATION_WORLD);
return loc->level;
}
GWeatherLocation *
gweather_location_get_parent (GWeatherLocation *loc)
{
+ g_return_val_if_fail (loc != NULL, NULL);
return loc->parent;
}
GWeatherLocation **
gweather_location_get_children (GWeatherLocation *loc)
{
+ g_return_val_if_fail (loc != NULL, NULL);
+
gweather_location_ref (loc);
if (loc->children)
return loc->children;
@@ -374,6 +384,8 @@
gweather_location_free_children (GWeatherLocation *loc,
GWeatherLocation **children)
{
+ g_return_if_fail (loc != NULL);
+
if (!loc->children)
g_free (children);
gweather_location_unref (loc);
@@ -382,6 +394,7 @@
gboolean
gweather_location_has_coords (GWeatherLocation *loc)
{
+ g_return_val_if_fail (loc != NULL, FALSE);
return loc->latlon_valid;
}
@@ -390,6 +403,9 @@
double *latitude, double *longitude)
{
//g_return_if_fail (loc->latlon_valid);
+ g_return_if_fail (loc != NULL);
+ g_return_if_fail (latitude != NULL);
+ g_return_if_fail (longitude != NULL);
*latitude = loc->latitude / M_PI * 180.0;
*longitude = loc->longitude / M_PI * 180.0;
@@ -401,6 +417,9 @@
/* average radius of the earth in km */
static const double radius = 6372.795;
+ g_return_val_if_fail (loc != NULL, 0);
+ g_return_val_if_fail (loc2 != NULL, 0);
+
//g_return_val_if_fail (loc->latlon_valid, 0.0);
//g_return_val_if_fail (loc2->latlon_valid, 0.0);
@@ -411,6 +430,8 @@
const char *
gweather_location_get_country (GWeatherLocation *loc)
{
+ g_return_val_if_fail (loc != NULL, NULL);
+
while (loc->parent && !loc->country_code)
loc = loc->parent;
return loc->country_code;
@@ -422,6 +443,8 @@
const char *tz_hint;
int i;
+ g_return_val_if_fail (loc != NULL, NULL);
+
while (loc && !loc->tz_hint)
loc = loc->parent;
if (!loc)
@@ -463,6 +486,8 @@
{
GPtrArray *zones;
+ g_return_val_if_fail (loc != NULL, NULL);
+
zones = g_ptr_array_new ();
add_timezones (loc, zones);
g_ptr_array_add (zones, NULL);
@@ -475,6 +500,9 @@
{
int i;
+ g_return_if_fail (loc != NULL);
+ g_return_if_fail (zones != NULL);
+
for (i = 0; zones[i]; i++)
gweather_timezone_unref (zones[i]);
g_free (zones);
@@ -483,12 +511,15 @@
const char *
gweather_location_get_code (GWeatherLocation *loc)
{
+ g_return_val_if_fail (loc != NULL, NULL);
return loc->station_code;
}
char *
gweather_location_get_city_name (GWeatherLocation *loc)
{
+ g_return_val_if_fail (loc != NULL, NULL);
+
if (loc->level == GWEATHER_LOCATION_CITY)
return g_strdup (loc->name);
else if (loc->level == GWEATHER_LOCATION_WEATHER_STATION &&
@@ -508,6 +539,8 @@
WeatherLocation *wloc;
char *coords;
+ g_return_val_if_fail (gloc != NULL, NULL);
+
if (!name)
name = gweather_location_get_name (gloc);
@@ -546,6 +579,8 @@
WeatherLocation *wloc;
WeatherInfo *info;
+ g_return_val_if_fail (loc != NULL, NULL);
+
wloc = gweather_location_to_weather_location (loc, NULL);
info = weather_info_new (wloc, NULL, NULL, NULL);
weather_location_free (wloc);
Modified: trunk/libgweather/gweather-prefs.c
==============================================================================
--- trunk/libgweather/gweather-prefs.c (original)
+++ trunk/libgweather/gweather-prefs.c Wed Nov 26 00:13:06 2008
@@ -280,6 +280,9 @@
GError *error = NULL;
gchar *gconf_str = NULL;
+ g_return_if_fail (prefs != NULL);
+ g_return_if_fail (ctx != NULL);
+
if (prefs->location) {
weather_location_free (prefs->location);
}
@@ -338,6 +341,9 @@
{
GWeatherPrefs prefs;
+ g_return_val_if_fail (str != NULL, TEMP_UNIT_INVALID);
+ g_return_val_if_fail (is_default != NULL, TEMP_UNIT_INVALID);
+
parse_temp_string (str, &prefs);
*is_default = prefs.use_temperature_default;
return prefs.temperature_unit;
@@ -348,6 +354,9 @@
{
GWeatherPrefs prefs;
+ g_return_val_if_fail (str != NULL, SPEED_UNIT_INVALID);
+ g_return_val_if_fail (is_default != NULL, SPEED_UNIT_INVALID);
+
parse_speed_string (str, &prefs);
*is_default = prefs.use_speed_default;
return prefs.speed_unit;
Modified: trunk/libgweather/gweather-timezone.c
==============================================================================
--- trunk/libgweather/gweather-timezone.c (original)
+++ trunk/libgweather/gweather-timezone.c Wed Nov 26 00:13:06 2008
@@ -238,6 +238,8 @@
GWeatherTimezone *
gweather_timezone_ref (GWeatherTimezone *zone)
{
+ g_return_val_if_fail (zone != NULL, NULL);
+
zone->ref_count++;
return zone;
}
@@ -245,6 +247,8 @@
void
gweather_timezone_unref (GWeatherTimezone *zone)
{
+ g_return_if_fail (zone != NULL);
+
if (!--zone->ref_count) {
g_free (zone->id);
g_free (zone->name);
@@ -270,30 +274,35 @@
const char *
gweather_timezone_get_name (GWeatherTimezone *zone)
{
+ g_return_val_if_fail (zone != NULL, NULL);
return zone->name;
}
const char *
gweather_timezone_get_tzid (GWeatherTimezone *zone)
{
+ g_return_val_if_fail (zone != NULL, NULL);
return zone->id;
}
int
gweather_timezone_get_offset (GWeatherTimezone *zone)
{
+ g_return_val_if_fail (zone != NULL, 0);
return zone->offset;
}
gboolean
gweather_timezone_has_dst (GWeatherTimezone *zone)
{
+ g_return_val_if_fail (zone != NULL, FALSE);
return zone->has_dst;
}
int
gweather_timezone_get_dst_offset (GWeatherTimezone *zone)
{
+ g_return_val_if_fail (zone != NULL, 0);
g_return_val_if_fail (zone->has_dst, 0);
return zone->dst_offset;
}
Modified: trunk/libgweather/timezone-menu.c
==============================================================================
--- trunk/libgweather/timezone-menu.c (original)
+++ trunk/libgweather/timezone-menu.c Wed Nov 26 00:13:06 2008
@@ -343,6 +343,8 @@
{
SetTimezoneData tzd;
+ g_return_if_fail (GWEATHER_IS_TIMEZONE_MENU (menu));
+
if (!tzid) {
gtk_combo_box_set_active (GTK_COMBO_BOX (menu), 0);
return;
@@ -357,6 +359,8 @@
const char *
gweather_timezone_menu_get_tzid (GWeatherTimezoneMenu *menu)
{
+ g_return_val_if_fail (GWEATHER_IS_TIMEZONE_MENU (menu), NULL);
+
if (!menu->zone)
return NULL;
return gweather_timezone_get_tzid (menu->zone);
Modified: trunk/libgweather/weather-sun.c
==============================================================================
--- trunk/libgweather/weather-sun.c (original)
+++ trunk/libgweather/weather-sun.c Wed Nov 26 00:13:06 2008
@@ -239,6 +239,8 @@
struct tm ltm;
time_t nxtEvent;
+ g_return_val_if_fail (info != NULL, -1);
+
if (!calc_sun (info))
return -1;
Modified: trunk/libgweather/weather.c
==============================================================================
--- trunk/libgweather/weather.c (original)
+++ trunk/libgweather/weather.c Wed Nov 26 00:13:06 2008
@@ -165,6 +165,8 @@
{
WeatherLocation *clone;
+ g_return_val_if_fail (location != NULL, NULL);
+
clone = weather_location_new (location->name,
location->code, location->zone,
location->radar, location->coordinates,
@@ -194,8 +196,14 @@
gboolean
weather_location_equal (const WeatherLocation *location1, const WeatherLocation *location2)
{
+ /* if something is NULL, then it's TRUE if and only if both are NULL) */
+ if (location1 == NULL || location2 == NULL)
+ return (location1 == location2);
if (!location1->code || !location2->code)
- return 1;
+ return (location1->code == location2->code);
+ if (!location1->name || !location2->name)
+ return (location1->name == location2->name);
+
return ((strcmp (location1->code, location2->code) == 0) &&
(strcmp (location1->name, location2->name) == 0));
}
@@ -537,6 +545,8 @@
void
weather_info_abort (WeatherInfo *info)
{
+ g_return_if_fail (info != NULL);
+
if (info->session) {
soup_session_abort (info->session);
info->requests_pending = 0;
@@ -624,7 +634,7 @@
void
weather_info_to_metric (WeatherInfo *info)
{
- g_return_if_fail(info != NULL);
+ g_return_if_fail (info != NULL);
info->temperature_unit = TEMP_UNIT_CENTIGRADE;
info->speed_unit = SPEED_UNIT_MS;
@@ -635,7 +645,7 @@
void
weather_info_to_imperial (WeatherInfo *info)
{
- g_return_if_fail(info != NULL);
+ g_return_if_fail (info != NULL);
info->temperature_unit = TEMP_UNIT_FAHRENHEIT;
info->speed_unit = SPEED_UNIT_MPH;
@@ -1074,8 +1084,8 @@
const gchar *
weather_info_get_temp_summary (WeatherInfo *info)
{
- if (!info)
- return NULL;
+ g_return_val_if_fail (info != NULL, NULL);
+
if (!info->valid || info->temp < -500.0)
return "--";
@@ -1106,7 +1116,9 @@
time_t current_time;
gboolean daytime;
- if (!info || !info->valid)
+ g_return_val_if_fail (info != NULL, NULL);
+
+ if (!info->valid)
return NULL;
cond = info->cond;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]