From 4e5ef4ef725f011fb214ce1816023be1cdd0bed8 Mon Sep 17 00:00:00 2001 From: Juergen Repp Date: Wed, 20 Mar 2024 09:06:47 +0100 Subject: [PATCH] FAPI: Fix warnings unused variable. * In ifapi_json_TPMS_POLICYAUTHORIZE_serialize it has to be checked whether the number of an optional condition is greater zero. * A warning "unused variable" if LOG_LEVEL == 0 is fixed. Signed-off-by: Juergen Repp --- src/tss2-fapi/ifapi_policy_json_serialize.c | 7 +++++++ src/tss2-fapi/tpm_json_deserialize.c | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/tss2-fapi/ifapi_policy_json_serialize.c b/src/tss2-fapi/ifapi_policy_json_serialize.c index 7dede08c4..a103576f5 100644 --- a/src/tss2-fapi/ifapi_policy_json_serialize.c +++ b/src/tss2-fapi/ifapi_policy_json_serialize.c @@ -793,6 +793,13 @@ ifapi_json_TPMS_POLICYAUTHORIZE_serialize(const TPMS_POLICYAUTHORIZE *in, return_error(TSS2_FAPI_RC_GENERAL_FAILURE, "Could not add json object."); } + /* Check whether only one condition field found in policy. */ + if (cond_cnt > 1) { + return_error(TSS2_FAPI_RC_BAD_VALUE, + "Exactly one conditional is allowed for policy " + "duplication select."); + } + return TSS2_RC_SUCCESS; } diff --git a/src/tss2-fapi/tpm_json_deserialize.c b/src/tss2-fapi/tpm_json_deserialize.c index 3edc4b717..bf51564d2 100644 --- a/src/tss2-fapi/tpm_json_deserialize.c +++ b/src/tss2-fapi/tpm_json_deserialize.c @@ -34,9 +34,11 @@ json_object* ifapi_parse_json(const char *jstring) { json_object *jso = NULL; enum json_tokener_error jerr; +#if MAXLOGLEVEL > 0 int line = 1; int line_offset = 0; int char_pos; +#endif struct json_tokener* tok = json_tokener_new(); if (!tok) { LOG_ERROR("Could not allocate json tokener"); @@ -45,6 +47,7 @@ ifapi_parse_json(const char *jstring) { jso = json_tokener_parse_ex(tok, jstring, -1); jerr = json_tokener_get_error(tok); if (jerr != json_tokener_success) { +#if MAXLOGLEVEL > 0 for (char_pos = 0; char_pos <= tok->char_offset; char_pos++) { if (jstring[char_pos] == '\n') { line++; @@ -55,6 +58,7 @@ ifapi_parse_json(const char *jstring) { } LOG_ERROR("Invalid JSON at line %i column %i: %s.", line, line_offset, json_tokener_error_desc(jerr)); +#endif json_tokener_free(tok); return NULL; }