MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / StrDecimalToUintnS

Function StrDecimalToUintnS

MdePkg/Library/BaseLib/SafeString.c:638–704  ·  view source on GitHub ↗

Convert a Null-terminated Unicode decimal string to a value of type UINTN. This function outputs a value of type UINTN by interpreting the contents of the Unicode string specified by String as a decimal number. The format of the input Unicode string String is: [spaces] [decimal digits]. The valid decimal digit character is in the range [0-9]. The function will

Source from the content-addressed store, hash-verified

636
637**/
638RETURN_STATUS
639EFIAPI
640StrDecimalToUintnS (
641 IN CONST CHAR16 *String,
642 OUT CHAR16 **EndPointer, OPTIONAL
643 OUT UINTN *Data
644 )
645{
646 ASSERT (((UINTN) String & BIT0) == 0);
647
648 //
649 // 1. Neither String nor Data shall be a null pointer.
650 //
651 SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER);
652 SAFE_STRING_CONSTRAINT_CHECK ((Data != NULL), RETURN_INVALID_PARAMETER);
653
654 //
655 // 2. The length of String shall not be greater than RSIZE_MAX.
656 //
657// if (RSIZE_MAX != 0) {
658// SAFE_STRING_CONSTRAINT_CHECK ((StrnLenS (String, RSIZE_MAX + 1) <= RSIZE_MAX), RETURN_INVALID_PARAMETER);
659// }
660
661 if (EndPointer != NULL) {
662 *EndPointer = (CHAR16 *) String;
663 }
664
665 //
666 // Ignore the pad spaces (space or tab)
667 //
668 while ((*String == L' ') || (*String == L'\t')) {
669 String++;
670 }
671
672 //
673 // Ignore leading Zeros after the spaces
674 //
675 while (*String == L'0') {
676 String++;
677 }
678
679 *Data = 0;
680
681 while (InternalIsDecimalDigitCharacter (*String)) {
682 //
683 // If the number represented by String overflows according to the range
684 // defined by UINTN, then MAX_UINTN is stored in *Data and
685 // RETURN_UNSUPPORTED is returned.
686 //
687// if (*Data > ((MAX_UINTN - (*String - L'0')) / 10)) {
688// *Data = MAX_UINTN;
689// if (EndPointer != NULL) {
690// *EndPointer = (CHAR16 *) String;
691// }
692// return RETURN_UNSUPPORTED;
693// ASSERT (*Data <= ((((UINTN) ~0) - (*String - L'0')) / 10));
694// }
695

Callers 3

StrToIpv6AddressFunction · 0.85
StrToIpv4AddressFunction · 0.85
StrDecimalToUintnFunction · 0.85

Calls 1

Tested by

no test coverage detected