hal: Branch 'master'
Danny Kukawka
dkukawka at kemper.freedesktop.org
Mon Jan 28 08:42:44 PST 2008
hald/util.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
New commits:
commit b6b9a0d16c452c168e53f78a4ba1370f4b4aaf34
Author: Danny Kukawka <danny.kukawka at web.de>
Date: Mon Jan 28 17:42:26 2008 +0100
added error handling for hal_util_get_*int*_from_file()
Added error handling for hal_util_get_*int*_from_file() which use
strtol() and strtoll() which can return 0 on error case. Check simply
errno for != 0.
diff --git a/hald/util.c b/hald/util.c
index a21b609..c6c6b80 100644
--- a/hald/util.c
+++ b/hald/util.c
@@ -179,6 +179,7 @@ hal_util_get_int_from_file (const gchar *directory, const gchar *file, gint *res
char buf[64];
gchar path[HAL_PATH_MAX];
gboolean ret;
+ gint _result;
f = NULL;
ret = FALSE;
@@ -196,9 +197,12 @@ hal_util_get_int_from_file (const gchar *directory, const gchar *file, gint *res
goto out;
}
- /* TODO: handle error condition */
- *result = strtol (buf, NULL, base);
- ret = TRUE;
+ errno = 0;
+ _result = strtol (buf, NULL, base);
+ if (errno == 0) {
+ ret = TRUE;
+ *result = _result;
+ }
out:
if (f != NULL)
@@ -229,6 +233,7 @@ hal_util_get_uint64_from_file (const gchar *directory, const gchar *file, guint6
char buf[64];
gchar path[HAL_PATH_MAX];
gboolean ret;
+ guint64 _result;
f = NULL;
ret = FALSE;
@@ -246,10 +251,12 @@ hal_util_get_uint64_from_file (const gchar *directory, const gchar *file, guint6
goto out;
}
- /* TODO: handle error condition */
- *result = strtoll (buf, NULL, base);
-
- ret = TRUE;
+ errno = 0;
+ _result = strtoll (buf, NULL, base);
+ if (errno == 0) {
+ ret = TRUE;
+ *result = _result;
+ }
out:
if (f != NULL)
@@ -451,6 +458,7 @@ hal_util_set_double_from_file (HalDevice *d, const gchar *key, const gchar *dire
ret = FALSE;
if ((buf = hal_util_get_string_from_file (directory, file)) != NULL) {
+ errno = 0;
value = strtod(buf, &end);
if (errno != ERANGE) {
ret = hal_device_property_set_double (d, key, value);
More information about the hal-commit
mailing list