format: Don't assert on errors in getters
authorArun Raghavan <arun.raghavan@collabora.co.uk>
Mon, 6 Feb 2012 05:50:17 +0000 (11:20 +0530)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Mon, 5 Mar 2012 14:30:31 +0000 (20:00 +0530)
This makes handling errors in getter functions more graceful, rather
than triggering warnings/asserts. Better to be less trigger-happy about
these things since this is now public-facing API.

src/pulse/format.c

index d37356d..4de6e89 100644 (file)
@@ -308,9 +308,14 @@ int pa_format_info_get_prop_int(pa_format_info *f, const char *key, int *v) {
     pa_assert(key);
     pa_assert(v);
 
-    pa_return_val_if_fail(str = pa_proplist_gets(f->plist, key), -PA_ERR_NOENTITY);
+    str = pa_proplist_gets(f->plist, key);
+    if (!str)
+        return -PA_ERR_NOENTITY;
+
     o = json_tokener_parse(str);
-    pa_return_val_if_fail(!is_error(o), -PA_ERR_INVALID);
+    if (is_error(o))
+        return -PA_ERR_INVALID;
+
     if (json_object_get_type(o) != json_type_int) {
         json_object_put(o);
         return -PA_ERR_INVALID;
@@ -335,7 +340,9 @@ int pa_format_info_get_prop_string(pa_format_info *f, const char *key, char **v)
         return -PA_ERR_NOENTITY;
 
     o = json_tokener_parse(str);
-    pa_return_val_if_fail(!is_error(o), -PA_ERR_INVALID);
+    if (is_error(o))
+        return -PA_ERR_INVALID;
+
     if (json_object_get_type(o) != json_type_string) {
         json_object_put(o);
         return -PA_ERR_INVALID;