libgweather r531 - in trunk: . libgweather
- From: vuntz svn gnome org
- To: svn-commits-list gnome org
- Subject: libgweather r531 - in trunk: . libgweather
- Date: Thu, 27 Nov 2008 13:39:03 +0000 (UTC)
Author: vuntz
Date: Thu Nov 27 13:39:03 2008
New Revision: 531
URL: http://svn.gnome.org/viewvc/libgweather?rev=531&view=rev
Log:
2008-11-27 Vincent Untz <vuntz gnome org>
* libgweather/weather.c:
(weather_wind_direction_string), (weather_sky_string),
(weather_conditions_string), (weather_info_get_icon_name),
(weather_info_get_value_sky), (weather_info_get_value_conditions),
(weather_info_get_value_wind), (weather_info_get_value_visibility):
have clearer & saner checks for validity of enum values.
(weather_location_new), (_weather_internal_check): internal consistency
checks
* libgweather/weather.h: add new enum values for LAST and INVALID
Fix bug #562283.
Modified:
trunk/ChangeLog
trunk/libgweather/weather.c
trunk/libgweather/weather.h
Modified: trunk/libgweather/weather.c
==============================================================================
--- trunk/libgweather/weather.c (original)
+++ trunk/libgweather/weather.c Thu Nov 27 13:39:03 2008
@@ -41,6 +41,8 @@
#include "weather.h"
#include "weather-priv.h"
+static void _weather_internal_check (void);
+
const char *
gweather_gettext (const char *str)
{
@@ -104,6 +106,8 @@
{
WeatherLocation *location;
+ _weather_internal_check ();
+
location = g_new (WeatherLocation, 1);
/* name and metar code must be set */
@@ -219,9 +223,7 @@
const gchar *
weather_wind_direction_string (WeatherWindDirection wind)
{
- if (wind < 0)
- return _("Unknown");
- if (wind >= (sizeof (wind_direction_str) / sizeof (char *)))
+ if (wind <= WIND_INVALID || wind >= WIND_LAST)
return _("Invalid");
return _(wind_direction_str[(int)wind]);
@@ -238,8 +240,7 @@
const gchar *
weather_sky_string (WeatherSky sky)
{
- if (sky < 0 ||
- sky >= (sizeof (sky_str) / sizeof (char *)))
+ if (sky <= SKY_INVALID || sky >= SKY_LAST)
return _("Invalid");
return _(sky_str[(int)sky]);
@@ -306,10 +307,10 @@
if (!cond.significant) {
return "-";
} else {
- if (cond.phenomenon >= 0 &&
- cond.phenomenon < 24 &&
- cond.qualifier >= 0 &&
- cond.qualifier < 13)
+ if (cond.phenomenon > PHENOMENON_INVALID &&
+ cond.phenomenon < PHENOMENON_LAST &&
+ cond.qualifier > QUALIFIER_INVALID &&
+ cond.qualifier < QUALIFIER_LAST)
str = _(conditions_str[(int)cond.phenomenon][(int)cond.qualifier]);
else
str = _("Invalid");
@@ -1130,6 +1131,8 @@
return "weather-storm";
switch (cond.phenomenon) {
+ case PHENOMENON_INVALID:
+ case PHENOMENON_LAST:
case PHENOMENON_NONE:
break;
@@ -1173,6 +1176,7 @@
switch (sky) {
case SKY_INVALID:
+ case SKY_LAST:
case SKY_CLEAR:
if (daytime)
return "weather-clear";
@@ -1349,7 +1353,7 @@
if (!info->valid)
return FALSE;
- if (info->sky < 0 || info->sky >= (sizeof (sky_str) / sizeof (char *)))
+ if (info->sky <= SKY_INVALID || info->sky >= SKY_LAST)
return FALSE;
*sky = info->sky;
@@ -1370,10 +1374,10 @@
if (!info->cond.significant)
return FALSE;
- if (!(info->cond.phenomenon >= 0 &&
- info->cond.phenomenon < 24 &&
- info->cond.qualifier >= 0 &&
- info->cond.qualifier < 13))
+ if (!(info->cond.phenomenon > PHENOMENON_INVALID &&
+ info->cond.phenomenon < PHENOMENON_LAST &&
+ info->cond.qualifier > QUALIFIER_INVALID &&
+ info->cond.qualifier < QUALIFIER_LAST))
return FALSE;
*phenomenon = info->cond.phenomenon;
@@ -1496,7 +1500,7 @@
if (!info->valid)
return FALSE;
- if (info->windspeed < 0.0 || info->wind < 0 || info->wind >= (sizeof (wind_direction_str) / sizeof (char *)))
+ if (info->windspeed < 0.0 || info->wind <= WIND_INVALID || info->wind >= WIND_LAST)
return FALSE;
res = speed_value (info->windspeed, unit, speed, info->speed_unit);
@@ -1528,3 +1532,12 @@
return distance_value (info->visibility, unit, value, info->distance_unit);
}
+
+static void
+_weather_internal_check (void)
+{
+ g_assert (G_N_ELEMENTS (wind_direction_str) == WIND_LAST);
+ g_assert (G_N_ELEMENTS (sky_str) == SKY_LAST);
+ g_assert (G_N_ELEMENTS (conditions_str) == PHENOMENON_LAST);
+ g_assert (G_N_ELEMENTS (conditions_str[0]) == QUALIFIER_LAST);
+}
Modified: trunk/libgweather/weather.h
==============================================================================
--- trunk/libgweather/weather.h (original)
+++ trunk/libgweather/weather.h Thu Nov 27 13:39:03 2008
@@ -177,11 +177,13 @@
/* values retrieving functions */
enum _WeatherWindDirection {
+ WIND_INVALID = -1,
WIND_VARIABLE,
WIND_N, WIND_NNE, WIND_NE, WIND_ENE,
WIND_E, WIND_ESE, WIND_SE, WIND_SSE,
WIND_S, WIND_SSW, WIND_SW, WIND_WSW,
- WIND_W, WIND_WNW, WIND_NW, WIND_NNW
+ WIND_W, WIND_WNW, WIND_NW, WIND_NNW,
+ WIND_LAST
};
typedef enum _WeatherWindDirection WeatherWindDirection;
@@ -192,12 +194,15 @@
SKY_BROKEN,
SKY_SCATTERED,
SKY_FEW,
- SKY_OVERCAST
+ SKY_OVERCAST,
+ SKY_LAST
};
typedef enum _WeatherSky WeatherSky;
enum _WeatherConditionPhenomenon {
+ PHENOMENON_INVALID = -1,
+
PHENOMENON_NONE,
PHENOMENON_DRIZZLE,
@@ -224,12 +229,16 @@
PHENOMENON_DUSTSTORM,
PHENOMENON_FUNNEL_CLOUD,
PHENOMENON_TORNADO,
- PHENOMENON_DUST_WHIRLS
+ PHENOMENON_DUST_WHIRLS,
+
+ PHENOMENON_LAST
};
typedef enum _WeatherConditionPhenomenon WeatherConditionPhenomenon;
enum _WeatherConditionQualifier {
+ QUALIFIER_INVALID = -1,
+
QUALIFIER_NONE,
QUALIFIER_VICINITY,
@@ -244,7 +253,9 @@
QUALIFIER_BLOWING,
QUALIFIER_SHOWERS,
QUALIFIER_DRIFTING,
- QUALIFIER_FREEZING
+ QUALIFIER_FREEZING,
+
+ QUALIFIER_LAST
};
typedef enum _WeatherConditionQualifier WeatherConditionQualifier;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]