From patchwork Sun Oct 14 21:16:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 191435 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 277942C0098 for ; Mon, 15 Oct 2012 08:16:14 +1100 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TNVXh-0000mY-0Z; Sun, 14 Oct 2012 21:16:13 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TNVXe-0000m5-4n for fwts-devel@lists.ubuntu.com; Sun, 14 Oct 2012 21:16:10 +0000 Received: from cpc3-craw6-2-0-cust180.croy.cable.virginmedia.com ([77.100.248.181] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1TNVXe-0004tA-1j for fwts-devel@lists.ubuntu.com; Sun, 14 Oct 2012 21:16:10 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH 2/3] lib: fwts_klog: use FWTS_JSON_ERROR macro for error checking Date: Sun, 14 Oct 2012 22:16:07 +0100 Message-Id: <1350249368-10846-3-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1350249368-10846-1-git-send-email-colin.king@canonical.com> References: <1350249368-10846-1-git-send-email-colin.king@canonical.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King 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 Acked-by: Keng-Yu Lin Acked-by: Ivan Hu --- 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; }