[PATCH 3/3] acpi: syntaxcheck: use FWTS_JSON_ERROR macro for error checking

Keng-Yu Lin kengyu at canonical.com
Wed Oct 17 08:15:49 UTC 2012


On Mon, Oct 15, 2012 at 5:16 AM, Colin King <colin.king at canonical.com> wrote:
> 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/acpi/syntaxcheck/syntaxcheck.c |   14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/src/acpi/syntaxcheck/syntaxcheck.c b/src/acpi/syntaxcheck/syntaxcheck.c
> index 4f5d43b..5ae7411 100644
> --- a/src/acpi/syntaxcheck/syntaxcheck.c
> +++ b/src/acpi/syntaxcheck/syntaxcheck.c
> @@ -29,8 +29,6 @@
>
>  #include <json/json.h>
>
> -#define JSON_ERROR      ((json_object*)-1)
> -
>  typedef struct {
>         uint16_t        error;
>         char            *advice;
> @@ -137,12 +135,14 @@ static int syntaxcheck_load_advice(fwts_framework *fw)
>
>         snprintf(json_data_path, sizeof(json_data_path), "%s/%s", fw->json_data_path, SYNTAXCHECK_JSON_FILE);
>
> -       if ((syntaxcheck_objs = json_object_from_file(json_data_path)) == JSON_ERROR) {
> +       syntaxcheck_objs = json_object_from_file(json_data_path);
> +       if (FWTS_JSON_ERROR(syntaxcheck_objs)) {
>                 fwts_log_error(fw, "Cannot load objects table from %s.", json_data_path);
>                 return FWTS_ERROR;
>         }
>
> -        if ((syntaxcheck_table = json_object_object_get(syntaxcheck_objs, "erroradvice")) == JSON_ERROR) {
> +        syntaxcheck_table = json_object_object_get(syntaxcheck_objs, "erroradvice");
> +        if (FWTS_JSON_ERROR(syntaxcheck_table)) {
>                  fwts_log_error(fw, "Cannot fetch syntaxcheck table from %s.", json_data_path);
>                  goto fail_put;
>          }
> @@ -160,13 +160,15 @@ static int syntaxcheck_load_advice(fwts_framework *fw)
>                 const char *str;
>                 json_object *obj;
>
> -               if ((obj = json_object_array_get_idx(syntaxcheck_table, i)) == JSON_ERROR) {
> +               obj = json_object_array_get_idx(syntaxcheck_table, i);
> +               if (FWTS_JSON_ERROR(obj)) {
>                         fwts_log_error(fw, "Cannot fetch %d item from syntaxcheck table.", i);
>                         free(adviceinfo);
>                         adviceinfo = NULL;
>                         break;
>                 }
> -               if ((str = json_object_get_string(json_object_object_get(obj, "advice"))) == NULL) {
> +               str = json_object_get_string(json_object_object_get(obj, "advice"));
> +               if (FWTS_JSON_ERROR(str)) {
>                         fwts_log_error(fw, "Cannot fetch advice from item %d.", i);
>                         free(adviceinfo);
>                         adviceinfo = NULL;
> --
> 1.7.10.4
>
Acked-by: Keng-Yu Lin <kengyu at canonical.com>



More information about the fwts-devel mailing list