diff options
author | Nickle Wang <nicklew@nvidia.com> | 2024-01-12 23:35:09 +0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2024-01-15 08:11:22 +0000 |
commit | d65b183f92446a3a2855c1c7dd4a7a1b760af381 (patch) | |
tree | 65826d9898aa91ac2a5d1934ebbc374235c9d93b /RedfishPkg/PrivateLibrary | |
parent | 6a01fb2ea5b3b142a98f3649b0947268f038f389 (diff) | |
download | edk2-d65b183f92446a3a2855c1c7dd4a7a1b760af381.zip edk2-d65b183f92446a3a2855c1c7dd4a7a1b760af381.tar.gz edk2-d65b183f92446a3a2855c1c7dd4a7a1b760af381.tar.bz2 |
RedfishPkg/RedfishCrtLib: handle floating point number in JSON
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 <nicklew@nvidia.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Nick Ramirez <nramirez@nvidia.com>
Reviewed-by: Abner Chang <abner.chang@amd.com>
Diffstat (limited to 'RedfishPkg/PrivateLibrary')
-rw-r--r-- | RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c index 57a997f..902dd0b 100644 --- a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c +++ b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c @@ -4,6 +4,7 @@ Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
+ Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -519,7 +520,7 @@ strtoull ( }
/**
- edk2 Jansson port does not support doubles, simply return 0.
+ edk2 Jansson port does not support doubles, simply return integer part.
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.
- @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 = 0;
+ StrLen = 0;
+
+ if (nptr == 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 != NULL) {
+ StrLen = AsciiStrLen (nptr);
+ *endptr = (char *__restrict)nptr + StrLen;
+ }
+
+ return (double)Data;
}
static UINT8 BitMask[] = {
|