[PATCH 2/3] lib: fwts_klog: use FWTS_JSON_ERROR macro for error checking
Colin King
colin.king at canonical.com
Sun Oct 14 21:16:07 UTC 2012
From: Colin Ian King <colin.king at canonical.com>
Use the new FWTS_JSON_ERROR macro to check for error
conditions to cope with the API change on json-c.
Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
src/lib/src/fwts_klog.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c
index 7787599..22f3b10 100644
--- a/src/lib/src/fwts_klog.c
+++ b/src/lib/src/fwts_klog.c
@@ -277,8 +277,6 @@ static fwts_compare_mode fwts_klog_compare_mode_str_to_val(const char *str)
return FWTS_COMPARE_UNKNOWN;
}
-#define JSON_ERROR ((json_object*)-1)
-
/*
* fwts_json_str()
* given a key, fetch the string value associated with this object
@@ -288,7 +286,8 @@ static const char *fwts_json_str(fwts_framework *fw, const char *table, int inde
{
const char *str;
- if ((str = json_object_get_string(json_object_object_get(obj, key))) == NULL) {
+ str = json_object_get_string(json_object_object_get(obj, key));
+ if (FWTS_JSON_ERROR(str)) {
fwts_log_error(fw, "Cannot fetch %s val from item %d, table %s.", key, index, table);
return NULL;
}
@@ -322,12 +321,14 @@ static int fwts_klog_check(fwts_framework *fw,
}
close(fd);
- if ((klog_objs = json_object_from_file(json_data_path)) == JSON_ERROR) {
+ klog_objs = json_object_from_file(json_data_path);
+ if (FWTS_JSON_ERROR(klog_objs)) {
fwts_log_error(fw, "Cannot load klog data from %s.", json_data_path);
return FWTS_ERROR;
}
- if ((klog_table = json_object_object_get(klog_objs, table)) == JSON_ERROR) {
+ klog_table = json_object_object_get(klog_objs, table);
+ if (FWTS_JSON_ERROR(klog_table)) {
fwts_log_error(fw, "Cannot fetch klog table object '%s' from %s.", table, json_data_path);
goto fail_put;
}
@@ -347,7 +348,8 @@ static int fwts_klog_check(fwts_framework *fw,
const char *str;
json_object *obj;
- if ((obj = json_object_array_get_idx(klog_table, i)) == JSON_ERROR) {
+ obj = json_object_array_get_idx(klog_table, i);
+ if (FWTS_JSON_ERROR(obj)) {
fwts_log_error(fw, "Cannot fetch %d item from table %s.", i, table);
goto fail;
}
--
1.7.10.4
More information about the fwts-devel
mailing list