From nobody Wed May 15 23:46:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+113780+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1705241644144761.3012965086289; Sun, 14 Jan 2024 06:14:04 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=sOEhbDLXpFXQzRje91Ng4JguIZEwkVZ9ASqeOJaRn08=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Received-SPF:From:To:CC:Subject:Date:Message-ID:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1705241643; v=1; b=D/5C80a/eUzKd8BAEqD/EdH1Q4mtNatfDObUNAyWGQ+qsxofgjfiT4S4JGgGs+bcrJ5PxeIG iYJ67e3eKgwBDYp965lVsM1w770Mpbk9gtH7WAKF/1T7FWBxkjWzrDGRGvodhTnmvOSY0Ir46Gt AZVnadlC2vZhuFsQ+iunMLQ0= X-Received: by 127.0.0.2 with SMTP id SZpvYY1788612xIrzXLdggs1; Sun, 14 Jan 2024 06:14:03 -0800 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.70]) by mx.groups.io with SMTP id smtpd.web11.38872.1705241642979732681 for ; Sun, 14 Jan 2024 06:14:03 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IE3X216ZVJsh/Tlf1TC6SPqJZ/oABMedy+/NwCUlUcHTplO5Q2vThW5NAYx5IgbPIoUCCPygQcNUsNnZuIauDivnFkIjp2QZ/qVL1N8IfegZIH6LWExmhj43XgroqgY1qgX2WZ/KTRN0+eHEd+5mWNpaLmw+TrM1nnNX28RcU6+tixGaQ+991GwcMHtpnSf6XxzmxgMt4nngbPJ8S6KG4p8NM7Zn1RnzaIxh2N3blUDBDL4S4Fi6zOe6lMc0K7qNiwno7r/Ij4ngo7K8PBOblpj4DHuH5pdZvnZIhxM1qeuPxHXbeQ21IbAAqTtwND2aClOrWkX6VnQ3BVavsRX9uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ph5fHWtm6zYrXqgEbTBZnmMfvqeQ1O6bSLpbyII/+Ec=; b=GfN89Msg1duT+jdVwM0YFEz01e3y33ZBB+JTW9zSTCQggfPAhIoyv6RTRM1Ff0BiBIKHsC55t9tVUWugI2hrPbkEIrr1cwZuxsYIxIKLWe+F0b08akiaBAibO7KGsOm9GJOwxzFeKD7/acwAV4cUrc5PX168uyn9eWYNJLKEy6vR1W6hqFOJIkaEdLMOimhdWooFqvlVLfLO66sd/kwBn+A/U3ta6wbQXTuyi6PfIDWcYBb1GRlochrg9+Q8DBHKlIAwkNnocX7OjFvpZC0FW3tBR5XuImPozGklhNRARkMc70f3eU8AKVGXIQVmBtSCY+vgC975lkfv4688XgEttA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) X-Received: from DM6PR07CA0105.namprd07.prod.outlook.com (2603:10b6:5:330::8) by PH0PR12MB7932.namprd12.prod.outlook.com (2603:10b6:510:280::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.17; Sun, 14 Jan 2024 14:13:58 +0000 X-Received: from DS2PEPF00003443.namprd04.prod.outlook.com (2603:10b6:5:330:cafe::c5) by DM6PR07CA0105.outlook.office365.com (2603:10b6:5:330::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.23 via Frontend Transport; Sun, 14 Jan 2024 14:13:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+113780+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C X-Received: from mail.nvidia.com (216.228.117.160) by DS2PEPF00003443.mail.protection.outlook.com (10.167.17.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.16 via Frontend Transport; Sun, 14 Jan 2024 14:13:57 +0000 X-Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 14 Jan 2024 06:13:45 -0800 X-Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 14 Jan 2024 06:13:45 -0800 X-Received: from NV-CL38DL3.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Sun, 14 Jan 2024 06:13:44 -0800 From: "Nickle Wang via groups.io" To: CC: Abner Chang , Igor Kulchytskyy , "Nick Ramirez" Subject: [edk2-devel] [PATCH v2] RedfishPkg/RedfishCrtLib: handle floating point number in JSON Date: Sun, 14 Jan 2024 22:13:46 +0800 Message-ID: <20240114141346.608-1-nicklew@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF00003443:EE_|PH0PR12MB7932:EE_ X-MS-Office365-Filtering-Correlation-Id: a78d7807-13fb-4114-7efb-08dc150b0ca7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: b8t+g74qnaMgW76mNZ36wDtH1ylAIv9QvlUJuqUx6kZtCO9v2PNFpwNtAnKEmaSIn/ti/eSwoXcE+A/+3D04FS9wWq9iCfpRjE4k1Qzmb1vxS5JD8WUE6d+Egnq5rEqIJXVv1Qw7XQWhjFK1/VOU8Sy9qgwqf8SfTt2FegL9Jxq7/Iwm/g65BsJLUmSB5ymsOffirTi0BPAriDy42CEsaXay+hFlQHZeQ2q6SOblnAfVXLGkV7Q7XugJzSQGkZb9C/HdeJl/h1CGS/6ml2sVNep4eWSUkYGwkCgwKaiG2RnXD0Yvj6oBquAswFnI0CMujC9Lya8ebPxFFJUod4F+tQfMWenmgGMuGTwYkte+WBbG05pbvkZAGjKW4T6fSdcE7cl5iV9B3VAZHnFdnoIAeMjcTO/4Ek35alKLV+kRxa01WoFtWYbYNUus4rbuFiz1LO5fQNGOTbkdLHuQOKYYVBVzFSupIQZxF9BeeuopptjZriflVUQUiAeIM2InMePLjEHhFRi/ODl3zKc2OGPvFnVBs3lUkNB1oPWxZbxUQhz7jJJlErymkSErxASz436nBu/kzuGALaWEz9e7/MQhs5Pw78Ckog8YuSwcxFt9kJlvw5rI0+6sUIxTtJIYei4EJhIBPZXoXkAHutMKFR9YtIcZbm81/O68BBVa+2Lx3G/O7+rBM9/WcEiGZTZjk+MAzMU+hdeFoq/LHiEvKpvdpUn15B2lsTDUXPAzT4M/4jHlcfAdrGNIleEG4PhnWENY X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2024 14:13:57.9332 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a78d7807-13fb-4114-7efb-08dc150b0ca7 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF00003443.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7932 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,nicklew@nvidia.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 39zk5xdVvXOnJJkZWUHRix3Mx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705241645585100003 Content-Type: text/plain; charset="utf-8" When the value type is defined as number in Redfish schema, floating point number is allowed. RedfishCrtLib raises assert without handling this case now. Follow the way in EDK2 to call AsciiStrDecimalToUintnS and handle the floating point number. Only the integer value is returned. Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Igor Kulchytskyy Cc: Nick Ramirez Reviewed-by: Abner Chang --- RedfishPkg/Library/JsonLib/load.c | 5 +-- .../RedfishCrtLib/RedfishCrtLib.c | 32 ++++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/RedfishPkg/Library/JsonLib/load.c b/RedfishPkg/Library/JsonLib= /load.c index 958c3ea8c5..1a3b4a6e6a 100644 --- a/RedfishPkg/Library/JsonLib/load.c +++ b/RedfishPkg/Library/JsonLib/load.c @@ -5,6 +5,7 @@ * it under the terms of the MIT license. See LICENSE for details. =20 (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. =20 SPDX-License-Identifier: BSD-2-Clause-Patent AND MIT */ @@ -717,8 +718,8 @@ lex_scan_number ( goto out; } =20 - lex->token =3D TOKEN_REAL; - lex->value.real =3D doubleval; + lex->token =3D TOKEN_INTEGER; + lex->value.integer =3D doubleval; return 0; =20 out: diff --git a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c b/Redf= ishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c index 57a997f351..902dd0b3a0 100644 --- a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c +++ b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c @@ -4,6 +4,7 @@ =20 Copyright (c) 2019, Intel Corporation. All rights reserved.
(C) Copyright 2020 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. =20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -519,7 +520,7 @@ strtoull ( } =20 /** - edk2 Jansson port does not support doubles, simply return 0. + edk2 Jansson port does not support doubles, simply return integer part. =20 These conversion functions convert the initial portion of the string pointed to by nptr to double, float, and long double representation, @@ -540,7 +541,7 @@ strtoull ( the return value), and ERANGE is stored in errno. If the correct value would cause underflow, zero is returned and ERANGE is stored in errno. =20 - @return Return 0. + @return Integer part of decimal number. **/ double strtod ( @@ -548,9 +549,30 @@ strtod ( char **__restrict endptr ) { - DEBUG ((DEBUG_ERROR, "We don't supprot double type on edk2 yet!")); - ASSERT (FALSE); - return (double)0; + UINTN Data; + UINTN StrLen; + + Data =3D 0; + StrLen =3D 0; + + if (nptr =3D=3D NULL) { + return (double)0; + } + + AsciiStrDecimalToUintnS (nptr, NULL, &Data); + DEBUG ((DEBUG_WARN, "%a: \"%a\" We don't support double type on edk2 yet= . Only integer part is returned: %d\n", __func__, nptr, Data)); + + // + // Force endptr to the last position of nptr because caller may + // check endptr and raise assertion. We don't support floating + // number in edk2 so this prevents unecessary assertion from happening. + // + if (endptr !=3D NULL) { + StrLen =3D AsciiStrLen (nptr); + *endptr =3D (char *__restrict)nptr + StrLen; + } + + return (double)Data; } =20 static UINT8 BitMask[] =3D { --=20 2.34.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113780): https://edk2.groups.io/g/devel/message/113780 Mute This Topic: https://groups.io/mt/103718898/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-