From: Jaben Carsey Date: Thu, 2 Jul 2015 17:26:42 +0000 (+0000) Subject: ShellPkg: fix string to number conversion with "0 " X-Git-Tag: edk2-stable201903~9458 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=80f3e34f7a4e0439dba7187753cba35699cc36b3 ShellPkg: fix string to number conversion with "0 " also fixes a few out of date comments. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jaben Carsey Reviewed-by: Tapan Shah Reviewed-by: Qiu Shumin git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17816 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c index 3521515468..0bf034f682 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -3729,7 +3729,7 @@ InternalShellHexCharToUintn ( /** Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64. - This function returns a value of type UINTN by interpreting the contents + This function returns a value of type UINT64 by interpreting the contents of the Unicode string specified by String as a hexadecimal number. The format of the input Unicode string String is: @@ -3797,16 +3797,16 @@ InternalShellStrHexToUint64 ( Result = 0; // - // Skip spaces if requested + // there is a space where there should't be // - while (StopAtSpace && *String == L' ') { - String++; + if (*String == L' ') { + return (EFI_INVALID_PARAMETER); } while (ShellIsHexaDecimalDigitCharacter (*String)) { // // If the Hex Number represented by String overflows according - // to the range defined by UINTN, then ASSERT(). + // to the range defined by UINT64, then return EFI_DEVICE_ERROR. // if (!(Result <= (RShiftU64((((UINT64) ~0) - InternalShellHexCharToUintn (*String)), 4)))) { // if (!(Result <= ((((UINT64) ~0) - InternalShellHexCharToUintn (*String)) >> 4))) { @@ -3889,15 +3889,18 @@ InternalShellStrDecimalToUint64 ( Result = 0; // - // Skip spaces if requested + // Stop upon space if requested + // (if the whole value was 0) // - while (StopAtSpace && *String == L' ') { - String++; + if (StopAtSpace && *String == L' ') { + *Value = Result; + return (EFI_SUCCESS); } + while (ShellIsDecimalDigitCharacter (*String)) { // // If the number represented by String overflows according - // to the range defined by UINT64, then ASSERT(). + // to the range defined by UINT64, then return EFI_DEVICE_ERROR. // if (!(Result <= (DivU64x32((((UINT64) ~0) - (*String - L'0')),10)))) {