From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by mx.groups.io with SMTP id smtpd.web11.11046.1611660638085355702 for ; Tue, 26 Jan 2021 03:30:38 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=BjRhIjN1; spf=pass (domain: nuviainc.com, ip: 209.85.128.48, mailfrom: leif@nuviainc.com) Received: by mail-wm1-f48.google.com with SMTP id u14so2407651wmq.4 for ; Tue, 26 Jan 2021 03:30:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Hx6/UbYrziaC2wrXTWj855SHeim6kkO0kOUF3PLVoYo=; b=BjRhIjN1xhlv4N6PkP1XHRtwYFAZ4lozG+Zo7olmu6vTBqVK8mv0WNgBaHDWd3BNnu hmrCosH03p1FfkCxJJZawuK3B97omzhBbTtzezHZGm/naHEnvxl48rWGMsu/dGqPrR7E ieELD3QAMs9Lpz8OYSbWPKuGkulzbt4jk4lsvAaRmRwnKnogulonONktgmkk2leAtz+F yrWbEku0RJKjtntPUhrxG9f6gk1HXTbU3qEqKnPmHfsUfw3riFxX35CAt9OnHibz6MR9 Wz3Gft8PciWz0WdB3rSi+uwy3QMEi2IB/RkWMb/1nH5+jAR5tdZgggjMvM5+MXKKTbUK 8+vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Hx6/UbYrziaC2wrXTWj855SHeim6kkO0kOUF3PLVoYo=; b=ZbmWC/AJM8o4yYfuZFqKNlXIADk/o5HBFGYpy9AjaIh0Fm3uu2F/yPwpoSFBHlSa4d A5oBbQjd+eRsfRV8pc9M8OkuhFGSIrYbp1OOkXNO25GFvazM5N2EaoimphhXf7sLetY2 6MokYK2NfP0ytyIyfHzLBsyZenGl3/EOC7oi+Kbu806HINgrL+x19ApfTNq5oIOSbrHO ePUlL3Zu4+o82vEaEfWZ58CZ63nPSzLkbcwVUujJM2oYdokXVkFUjeFqklio0tra4sg/ 3fm3A0+b3YxAMZzvzwcH54WbtGWDlnjiliwMQv9ZxuXqgoWLHI67KCCNCYH2Ii93CcEA Vd6Q== X-Gm-Message-State: AOAM532NoGj5pe3wxIZo7NCyhWOUsyG4sHyzezFJVuvsDeRdKgD099rm cdtjlYG8WA7t8El/r9QKNkh1qEtfOXZHyRDlNoR9HvI4rla3g+UC/pHtjDuAmn6rg4B6Qbk45Uu Cyl5ugye7sl+Xkg7NUD/fO0Aoz6kV7SEmneTnFNdPBraNMOUk9pZnpuUhHQw8RFZfKXf1 X-Google-Smtp-Source: ABdhPJy7xnUqYNRB63DKCbfNbL72kLEA0B1rrDTMen4SnNAb03hZlho7Mi3gzYu5M7QXzCB0BRpeaw== X-Received: by 2002:a1c:7d0c:: with SMTP id y12mr4270977wmc.184.1611660636428; Tue, 26 Jan 2021 03:30:36 -0800 (PST) Return-Path: Received: from vanye (cpc1-cmbg19-2-0-cust915.5-4.cable.virginm.net. [82.27.183.148]) by smtp.gmail.com with ESMTPSA id v126sm2984455wma.22.2021.01.26.03.30.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 03:30:35 -0800 (PST) Date: Tue, 26 Jan 2021 11:30:34 +0000 From: "Leif Lindholm" To: devel@edk2.groups.io, abner.chang@hpe.com Cc: Nickle Wang , Michael D Kinney Subject: Re: [edk2-devel] [PATCH] RedfishPkg/JsonLib: Fix build errors Message-ID: <20210126113034.GO1664@vanye> References: <20210125043154.20645-1-abner.chang@hpe.com> MIME-Version: 1.0 In-Reply-To: <20210125043154.20645-1-abner.chang@hpe.com> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi Abner, On Mon, Jan 25, 2021 at 12:31:54 +0800, Abner Chang wrote: > This patch fixes the build errors when build JsonLib with EDK2 > Redfish feature driver. > > - Add JsonLoadString function to load a NULL terminated-string JSON > - json_string_value() in JsonValueGetAsciiString () is removed > by accident. > > Signed-off-by: Abner Chang > > Cc: Leif Lindholm > Cc: Nickle Wang > Cc: Michael D Kinney > --- > RedfishPkg/Library/JsonLib/JsonLib.inf | 5 +++-- > RedfishPkg/Include/Library/JsonLib.h | 21 ++++++++++++++++++ > RedfishPkg/Library/JsonLib/JsonLib.c | 30 ++++++++++++++++++++++++-- > 3 files changed, 52 insertions(+), 4 deletions(-) > > diff --git a/RedfishPkg/Library/JsonLib/JsonLib.inf b/RedfishPkg/Library/JsonLib/JsonLib.inf > index 48b094a78a..9d52a622e1 100644 > --- a/RedfishPkg/Library/JsonLib/JsonLib.inf > +++ b/RedfishPkg/Library/JsonLib/JsonLib.inf > @@ -75,12 +75,13 @@ > # C4244: conversion from type1 to type2, possible loss of data > # C4334: 32-bit shift implicitly converted to 64-bit > # C4204: nonstandard extension used: non-constant aggregate initializer > + # C4706: assignment within conditional expression > # > # Define macro HAVE_CONFIG_H to include jansson_private_config.h to build. > # Undefined _WIN32, WIN64, _MSC_VER macros > # On GCC, no error on the unused-function and unused-but-set-variable. > # > - MSFT:*_*_X64_CC_FLAGS = /wd4204 /wd4244 /wd4090 /wd4334 /DHAVE_CONFIG_H=1 /U_WIN32 /UWIN64 /U_MSC_VER > - MSFT:*_*_IA32_CC_FLAGS = /wd4204 /wd4244 /wd4090 /DHAVE_CONFIG_H=1 /U_WIN32 /UWIN64 /U_MSC_VER > + MSFT:*_*_X64_CC_FLAGS = /wd4204 /wd4244 /wd4090 /wd4334 /wd4706 /DHAVE_CONFIG_H=1 /U_WIN32 /UWIN64 /U_MSC_VER > + MSFT:*_*_IA32_CC_FLAGS = /wd4204 /wd4244 /wd4090 /wd4706 /DHAVE_CONFIG_H=1 /U_WIN32 /UWIN64 /U_MSC_VER Urgh, please don't do this. C4706 is what gives you a warning for accidentally assigning instead of comparing. It's our last defence against the jeopardy-comparing hordes that think if (NULL == Ptr) is a sensible way of writing C. What is the actual problem being encountered? Beyond that, this will probably be an issue for all architectures, so why add explicit (identical) workarounds for IA32/X64? Secondly, I understand these changes were added for a single reason "fix build failures" - but these are two distinct changes, so should be two distinct patches. / Leif > GCC:*_*_*_CC_FLAGS = -Wno-unused-function -Wno-unused-but-set-variable > > diff --git a/RedfishPkg/Include/Library/JsonLib.h b/RedfishPkg/Include/Library/JsonLib.h > index 3c10f67d27..82ca4bad60 100644 > --- a/RedfishPkg/Include/Library/JsonLib.h > +++ b/RedfishPkg/Include/Library/JsonLib.h > @@ -664,6 +664,27 @@ JsonDumpString ( > IN UINTN Flags > ); > > +/** > + Convert a string to JSON object. > + The function is used to convert a NULL terminated UTF8 encoded string to a JSON > + value. Only object and array represented strings can be converted successfully, > + since they are the only valid root values of a JSON text for UEFI usage. > + > + Real number and number with exponent part are not supportted by UEFI. > + > + Caller needs to cleanup the root value by calling JsonValueFree(). > + > + @param[in] String The NULL terminated UTF8 encoded string to convert > + > + @retval Array JSON value or object JSON value, or NULL when any error occurs. > + > +**/ > +EDKII_JSON_VALUE > +EFIAPI > +JsonLoadString ( > + IN CONST CHAR8* String > + ); > + > /** > Load JSON from a buffer. > > diff --git a/RedfishPkg/Library/JsonLib/JsonLib.c b/RedfishPkg/Library/JsonLib/JsonLib.c > index 34ff381aee..1762c6f5af 100644 > --- a/RedfishPkg/Library/JsonLib/JsonLib.c > +++ b/RedfishPkg/Library/JsonLib/JsonLib.c > @@ -430,10 +430,10 @@ JsonValueGetAsciiString ( > IN EDKII_JSON_VALUE Json > ) > { > - CHAR8 *AsciiStr; > + CONST CHAR8 *AsciiStr; > UINTN Index; > > - AsciiStr = (CHAR8 *) ((json_t *) Json); > + AsciiStr = json_string_value ((json_t *) Json); > if (AsciiStr == NULL) { > return NULL; > } > @@ -819,6 +819,32 @@ JsonDumpString ( > return json_dumps((json_t *)JsonValue, Flags); > } > > +/** > + Convert a string to JSON object. > + The function is used to convert a NULL terminated UTF8 encoded string to a JSON > + value. Only object and array represented strings can be converted successfully, > + since they are the only valid root values of a JSON text for UEFI usage. > + > + Real number and number with exponent part are not supportted by UEFI. > + > + Caller needs to cleanup the root value by calling JsonValueFree(). > + > + @param[in] String The NULL terminated UTF8 encoded string to convert > + > + @retval Array JSON value or object JSON value, or NULL when any error occurs. > + > +**/ > +EDKII_JSON_VALUE > +EFIAPI > +JsonLoadString ( > + IN CONST CHAR8* String > + ) > +{ > + json_error_t JsonError; > + > + return (EDKII_JSON_VALUE) json_loads ((const char *)String, 0, &JsonError); > +} > + > /** > Load JSON from a buffer. > > -- > 2.17.1 > > > > > >