X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FBasePrintLib%2FPrintLib.c;h=455fd60526f4d894ef055c4db2e58286e7cddcad;hb=2be54d60f1182b85003433d03466df9822e20697;hp=24e01755451352ad7af165cd77b0047abe63f8f6;hpb=533f039eb0bd2a1d5e7f11debb1379b048630021;p=mirror_edk2.git diff --git a/MdePkg/Library/BasePrintLib/PrintLib.c b/MdePkg/Library/BasePrintLib/PrintLib.c index 24e0175545..455fd60526 100644 --- a/MdePkg/Library/BasePrintLib/PrintLib.c +++ b/MdePkg/Library/BasePrintLib/PrintLib.c @@ -16,63 +16,58 @@ #include "PrintLibInternal.h" -typedef struct { - RETURN_STATUS Status; - CHAR8 *String; -} STATUS_LOOKUP_TABLE_ENTRY; - -static CONST STATUS_LOOKUP_TABLE_ENTRY StatusString[] = { - { RETURN_SUCCESS, "Success" }, - { RETURN_LOAD_ERROR, "Load Error" }, - { RETURN_INVALID_PARAMETER, "Invalid Parameter" }, - { RETURN_UNSUPPORTED, "Unsupported" }, - { RETURN_BAD_BUFFER_SIZE, "Bad Buffer Size" }, - { RETURN_BUFFER_TOO_SMALL, "Buffer Too Small" }, - { RETURN_NOT_READY, "Not Ready" }, - { RETURN_DEVICE_ERROR, "Device Error" }, - { RETURN_WRITE_PROTECTED, "Write Protected" }, - { RETURN_OUT_OF_RESOURCES, "Out of Resources" }, - { RETURN_VOLUME_CORRUPTED, "Volume Corrupt" }, - { RETURN_VOLUME_FULL, "Volume Full" }, - { RETURN_NO_MEDIA, "No Media" }, - { RETURN_MEDIA_CHANGED, "Media changed" }, - { RETURN_NOT_FOUND, "Not Found" }, - { RETURN_ACCESS_DENIED, "Access Denied" }, - { RETURN_NO_RESPONSE, "No Response" }, - { RETURN_NO_MAPPING, "No mapping" }, - { RETURN_TIMEOUT, "Time out" }, - { RETURN_NOT_STARTED, "Not started" }, - { RETURN_ALREADY_STARTED, "Already started" }, - { RETURN_ABORTED, "Aborted" }, - { RETURN_ICMP_ERROR, "ICMP Error" }, - { RETURN_TFTP_ERROR, "TFTP Error" }, - { RETURN_PROTOCOL_ERROR, "Protocol Error" }, - { RETURN_WARN_UNKNOWN_GLYPH, "Warning Unknown Glyph" }, - { RETURN_WARN_DELETE_FAILURE, "Warning Delete Failure" }, - { RETURN_WARN_WRITE_FAILURE, "Warning Write Failure" }, - { RETURN_WARN_BUFFER_TOO_SMALL, "Warning Buffer Too Small" }, - { 0, NULL } +#define WARNING_STATUS_NUMBER 4 +#define ERROR_STATUS_NUMBER 24 + +STATIC CONST CHAR8 *StatusString [] = { + "Success", // RETURN_SUCCESS = 0 + "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1 + "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE = 2 + "Warning Write Failure", // RETURN_WARN_WRITE_FAILURE = 3 + "Warning Buffer Too Small", // RETURN_WARN_BUFFER_TOO_SMALL = 4 + "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT + "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT + "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT + "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT + "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT + "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT + "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT + "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT + "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT + "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT + "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT + "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT + "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT + "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT + "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT + "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT + "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT + "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT + "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT + "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT + "Aborted", // RETURN_ABORTED = 21 | MAX_BIT + "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT + "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT + "Protocol Error" // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT }; - /** Worker function that produces a Null-terminated string in an output buffer based on a Null-terminated format string and a VA_LIST argument list. VSPrint function to process format and place the results in Buffer. Since a VA_LIST is used this rountine allows the nesting of Vararg routines. Thus - this is the main print working routine + this is the main print working routine. @param Buffer Character buffer to print the results of the parsing of Format into. @param BufferSize Maximum number of characters to put into buffer. - Zero means no limit. @param Flags Intial flags value. - Can only have FORMAT_UNICODE and OUTPUT_UNICODE set + Can only have FORMAT_UNICODE and OUTPUT_UNICODE set. @param Format Null-terminated format string. @param Marker Vararg list consumed by processing Format. - @return Number of characters printed. + @return Number of characters printed not including the Null-terminator. **/ UINTN @@ -85,6 +80,7 @@ BasePrintLibVSPrint ( ) { CHAR8 *OriginalBuffer; + CHAR8 *EndBuffer; CHAR8 ValueBuffer[MAXIMUM_VALUE_CHARACTERS]; UINTN BytesPerOutputCharacter; UINTN BytesPerFormatCharacter; @@ -93,7 +89,7 @@ BasePrintLibVSPrint ( UINTN Width; UINTN Precision; INT64 Value; - CHAR8 *ArgumentString; + CONST CHAR8 *ArgumentString; UINTN Character; GUID *TmpGuid; TIME *TmpTime; @@ -110,29 +106,46 @@ BasePrintLibVSPrint ( UINTN Radix; RETURN_STATUS Status; + if (BufferSize == 0) { + return 0; + } ASSERT (Buffer != NULL); - ASSERT (Format != NULL); - - OriginalBuffer = Buffer; if ((Flags & OUTPUT_UNICODE) != 0) { BytesPerOutputCharacter = 2; } else { BytesPerOutputCharacter = 1; } + + // + // Reserve space for the Null terminator. + // + BufferSize--; + OriginalBuffer = Buffer; + // + // Set the tag for the end of the input Buffer. + // + EndBuffer = Buffer + BufferSize * BytesPerOutputCharacter; + if ((Flags & FORMAT_UNICODE) != 0) { + // + // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength + // Unicode characters if PcdMaximumUnicodeStringLength is not zero. + // + ASSERT (StrSize ((CHAR16 *) Format) != 0); BytesPerFormatCharacter = 2; FormatMask = 0xffff; } else { + // + // Make sure format string cannot contain more than PcdMaximumAsciiStringLength + // Ascii characters if PcdMaximumAsciiStringLength is not zero. + // + ASSERT (AsciiStrSize (Format) != 0); BytesPerFormatCharacter = 1; FormatMask = 0xff; } - // - // Reserve space for the Null terminator. - // If BufferSize is 0, this will set BufferSize to the max unsigned value - // - BufferSize--; + // // Get the first character from the format string @@ -142,7 +155,7 @@ BasePrintLibVSPrint ( // // Loop until the end of the format string is reached or the output buffer is full // - while (FormatCharacter != 0 && BufferSize > 0) { + while (FormatCharacter != 0 && Buffer < EndBuffer) { // // Clear all the flag bits except those that may have been passed in // @@ -221,36 +234,44 @@ BasePrintLibVSPrint ( Precision = Count; } break; + + case '\0': + // + // Make no output if Format string terminates unexpectedly when + // looking up for flag, width, precision and type. + // + Format -= BytesPerFormatCharacter; + Precision = 0; + // + // break skipped on purpose. + // default: Done = TRUE; break; } } - // - // Limit the maximum field width to the remaining characters in the output buffer - // - if (Width > BufferSize) { - Width = BufferSize; - } - // // Handle each argument type // switch (FormatCharacter) { case 'p': + // + // Flag space, +, 0, L & l are invalid for type p. + // + Flags &= ~(PREFIX_BLANK | PREFIX_SIGN | PREFIX_ZERO | LONG_TYPE); if (sizeof (VOID *) > 4) { Flags |= LONG_TYPE; } case 'X': Flags |= PREFIX_ZERO; // - // break skiped on purpose + // break skipped on purpose // case 'x': Flags |= RADIX_HEX; // - // break skiped on purpose + // break skipped on purpose // case 'd': if ((Flags & LONG_TYPE) == 0) { @@ -293,19 +314,26 @@ BasePrintLibVSPrint ( Count = 0; } ArgumentString = (CHAR8 *)ValueBuffer + Count; - Digits = 3 - (Count % 3); + + Digits = Count % 3; + if (Digits != 0) { + Digits = 3 - Digits; + } if (Comma && Count != 0) { Count += ((Count - 1) / 3); } if (Prefix != 0) { Count++; + Precision++; } Flags |= ARGUMENT_REVERSED; ZeroPad = TRUE; if ((Flags & PREFIX_ZERO) != 0) { - if ((Flags & PAD_TO_WIDTH) != 0) { - if ((Flags & PRECISION) == 0) { - Precision = Width; + if ((Flags & LEFT_JUSTIFY) == 0) { + if ((Flags & PAD_TO_WIDTH) != 0) { + if ((Flags & PRECISION) == 0) { + Precision = Width; + } } } } @@ -338,7 +366,7 @@ BasePrintLibVSPrint ( } else { BasePrintLibSPrint ( ValueBuffer, - 0, + MAXIMUM_VALUE_CHARACTERS, 0, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", TmpGuid->Data1, @@ -364,7 +392,7 @@ BasePrintLibVSPrint ( } else { BasePrintLibSPrint ( ValueBuffer, - 0, + MAXIMUM_VALUE_CHARACTERS, 0, "%02d/%02d/%04d %02d:%02d", TmpTime->Month, @@ -380,16 +408,29 @@ BasePrintLibVSPrint ( case 'r': Status = VA_ARG (Marker, RETURN_STATUS); ArgumentString = ValueBuffer; - for (Index = 0; StatusString[Index].String != NULL; Index++) { - if (Status == StatusString[Index].Status) { - ArgumentString = StatusString[Index].String; + if (RETURN_ERROR (Status)) { + // + // Clear error bit + // + Index = Status & ~MAX_BIT; + if (Index > 0 && Index <= ERROR_STATUS_NUMBER) { + ArgumentString = StatusString [Index + WARNING_STATUS_NUMBER]; + } + } else { + Index = Status; + if (Index <= WARNING_STATUS_NUMBER) { + ArgumentString = StatusString [Index]; } } if (ArgumentString == ValueBuffer) { - BasePrintLibSPrint ((CHAR8 *) ValueBuffer, 0, 0, "%08X", Status); + BasePrintLibSPrint ((CHAR8 *) ValueBuffer, MAXIMUM_VALUE_CHARACTERS, 0, "%08X", Status); } break; + case '\n': + ArgumentString = "\n\r"; + break; + case '%': default: // @@ -400,9 +441,11 @@ BasePrintLibVSPrint ( break; } break; + case '\n': - ArgumentString = "\r\n"; + ArgumentString = "\n\r"; break; + default: ArgumentString = (CHAR8 *)&FormatCharacter; Flags |= ARGUMENT_UNICODE; @@ -434,12 +477,6 @@ BasePrintLibVSPrint ( } } - // - // Limit the length of the string to append to the remaining characters in the output buffer - // - if (Count > BufferSize) { - Count = BufferSize; - } if (Precision < Count) { Precision = Count; } @@ -448,18 +485,18 @@ BasePrintLibVSPrint ( // Pad before the string // if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) { - Buffer = BasePrintLibFillBuffer (Buffer, Width - Precision, ' ', BytesPerOutputCharacter); + Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter); } if (ZeroPad) { if (Prefix != 0) { - Buffer = BasePrintLibFillBuffer (Buffer, 1, Prefix, BytesPerOutputCharacter); + Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter); } - Buffer = BasePrintLibFillBuffer (Buffer, Precision - Count, '0', BytesPerOutputCharacter); + Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, '0', BytesPerOutputCharacter); } else { - Buffer = BasePrintLibFillBuffer (Buffer, Precision - Count, ' ', BytesPerOutputCharacter); + Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, ' ', BytesPerOutputCharacter); if (Prefix != 0) { - Buffer = BasePrintLibFillBuffer (Buffer, 1, Prefix, BytesPerOutputCharacter); + Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter); } } @@ -467,7 +504,7 @@ BasePrintLibVSPrint ( // Output the Prefix character if it is present // Index = 0; - if (Prefix) { + if (Prefix != 0) { Index++; } @@ -477,7 +514,7 @@ BasePrintLibVSPrint ( while (Index < Count) { ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask; - Buffer = BasePrintLibFillBuffer (Buffer, 1, ArgumentCharacter, BytesPerOutputCharacter); + Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ArgumentCharacter, BytesPerOutputCharacter); ArgumentString += BytesPerArgumentCharacter; Index++; if (Comma) { @@ -486,7 +523,7 @@ BasePrintLibVSPrint ( Digits = 0; Index++; if (Index < Count) { - Buffer = BasePrintLibFillBuffer (Buffer, 1, ',', BytesPerOutputCharacter); + Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ',', BytesPerOutputCharacter); } } } @@ -496,14 +533,9 @@ BasePrintLibVSPrint ( // Pad after the string // if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) { - Buffer = BasePrintLibFillBuffer (Buffer, Width - Precision, ' ', BytesPerOutputCharacter); + Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter); } - // - // Reduce the number of characters - // - BufferSize -= Count; - // // Get the next character from the format string // @@ -518,8 +550,18 @@ BasePrintLibVSPrint ( // // Null terminate the Unicode or ASCII string // - Buffer = BasePrintLibFillBuffer (Buffer, 1, 0, BytesPerOutputCharacter); - + BasePrintLibFillBuffer (Buffer, EndBuffer + BytesPerOutputCharacter, 1, 0, BytesPerOutputCharacter); + // + // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength + // Unicode characters if PcdMaximumUnicodeStringLength is not zero. + // + ASSERT ((((Flags & OUTPUT_UNICODE) == 0)) || (StrSize ((CHAR16 *) OriginalBuffer) != 0)); + // + // Make sure output buffer cannot contain more than PcdMaximumAsciiStringLength + // ASCII characters if PcdMaximumAsciiStringLength is not zero. + // + ASSERT ((((Flags & OUTPUT_UNICODE) != 0)) || (AsciiStrSize (OriginalBuffer) != 0)); + return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter); } @@ -529,7 +571,7 @@ BasePrintLibVSPrint ( VSPrint function to process format and place the results in Buffer. Since a VA_LIST is used this rountine allows the nesting of Vararg routines. Thus - this is the main print working routine + this is the main print working routine. @param Buffer Character buffer to print the results of the parsing of Format into. @@ -539,7 +581,7 @@ BasePrintLibVSPrint ( Can only have FORMAT_UNICODE and OUTPUT_UNICODE set @param FormatString Null-terminated format string. - @return Number of characters printed. + @return Number of characters printed not including the Null-terminator. **/ UINTN @@ -566,23 +608,27 @@ BasePrintLibSPrint ( The Unicode string is produced by parsing the format string specified by FormatString. Arguments are pulled from the variable argument list specified by Marker based on the contents of the format string. - The length of the produced output buffer is returned. - If BufferSize is 0, then no output buffer is produced and 0 is returned. + The number of Unicode characters in the produced output buffer is returned not including + the Null-terminator. + If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned. - If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize is not 0 and FormatString is NULL, then ASSERT(). + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). + If BufferSize > 1 and FormatString is NULL, then ASSERT(). If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than - PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then + ASSERT(). If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + contains more than PcdMaximumUnicodeStringLength Unicode characters not including the + Null-terminator, then ASSERT(). - @param StartOfBuffer APointer to the output buffer for the produced Null-terminated + @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. @param FormatString Null-terminated Unicode format string. @param Marker VA_LIST marker for the variable argument list. - @return return Length of the produced output buffer. + @return The number of Unicode characters in the produced output buffer not including the + Null-terminator. **/ UINTN @@ -605,22 +651,26 @@ UnicodeVSPrint ( and BufferSize. The Unicode string is produced by parsing the format string specified by FormatString. Arguments are pulled from the variable argument list based on the contents of the format string. - The length of the produced output buffer is returned. - If BufferSize is 0, then no output buffer is produced and 0 is returned. + The number of Unicode characters in the produced output buffer is returned not including + the Null-terminator. + If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned. - If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize is not 0 and FormatString is NULL, then ASSERT(). + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). + If BufferSize > 1 and FormatString is NULL, then ASSERT(). If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than - PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then + ASSERT(). If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + contains more than PcdMaximumUnicodeStringLength Unicode characters not including the + Null-terminator, then ASSERT(). - @param StartOfBuffer APointer to the output buffer for the produced Null-terminated + @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. @param FormatString Null-terminated Unicode format string. - @return Length of the produced output buffer. + @return The number of Unicode characters in the produced output buffer not including the + Null-terminator. **/ UINTN @@ -647,23 +697,27 @@ UnicodeSPrint ( The Unicode string is produced by parsing the format string specified by FormatString. Arguments are pulled from the variable argument list specified by Marker based on the contents of the format string. - The length of the produced output buffer is returned. - If BufferSize is 0, then no output buffer is produced and 0 is returned. - - If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize is not 0 and FormatString is NULL, then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than - PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + The number of Unicode characters in the produced output buffer is returned not including + the Null-terminator. + If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned. + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). + If BufferSize > 1 and FormatString is NULL, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than + PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then + ASSERT(). If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + contains more than PcdMaximumUnicodeStringLength Unicode characters not including the + Null-terminator, then ASSERT(). - @param StartOfBuffer APointer to the output buffer for the produced Null-terminated + @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. @param FormatString Null-terminated Unicode format string. @param Marker VA_LIST marker for the variable argument list. - @return Length of the produced output buffer. + @return The number of Unicode characters in the produced output buffer not including the + Null-terminator. **/ UINTN @@ -687,22 +741,26 @@ UnicodeVSPrintAsciiFormat ( The Unicode string is produced by parsing the format string specified by FormatString. Arguments are pulled from the variable argument list based on the contents of the format string. - The length of the produced output buffer is returned. - If BufferSize is 0, then no output buffer is produced and 0 is returned. - - If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize is not 0 and FormatString is NULL, then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than - PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + The number of Unicode characters in the produced output buffer is returned not including + the Null-terminator. + If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned. + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). + If BufferSize > 1 and FormatString is NULL, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than + PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then + ASSERT(). If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + contains more than PcdMaximumUnicodeStringLength Unicode characters not including the + Null-terminator, then ASSERT(). - @param StartOfBuffer APointer to the output buffer for the produced Null-terminated + @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. @param FormatString Null-terminated Unicode format string. - @return Length of the produced output buffer. + @return The number of Unicode characters in the produced output buffer not including the + Null-terminator. **/ UINTN @@ -717,7 +775,7 @@ UnicodeSPrintAsciiFormat ( VA_LIST Marker; VA_START (Marker, FormatString); - return UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize >> 1, FormatString, Marker); + return UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker); } /** @@ -729,23 +787,27 @@ UnicodeSPrintAsciiFormat ( The ASCII string is produced by parsing the format string specified by FormatString. Arguments are pulled from the variable argument list specified by Marker based on the contents of the format string. - The length of the produced output buffer is returned. + The number of ASCII characters in the produced output buffer is returned not including + the Null-terminator. If BufferSize is 0, then no output buffer is produced and 0 is returned. - If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize is not 0 and FormatString is NULL, then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than - PcdMaximumUnicodeStringLength ASCII characters, then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string - contains more than PcdMaximumUnicodeStringLength ASCII characters, then ASSERT(). + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). + If BufferSize > 0 and FormatString is NULL, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than + PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then + ASSERT(). + If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string + contains more than PcdMaximumAsciiStringLength ASCII characters not including the + Null-terminator, then ASSERT(). - @param StartOfBuffer APointer to the output buffer for the produced Null-terminated + @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. @param FormatString Null-terminated Unicode format string. @param Marker VA_LIST marker for the variable argument list. - @return Length of the produced output buffer. + @return The number of ASCII characters in the produced output buffer not including the + Null-terminator. **/ UINTN @@ -769,22 +831,26 @@ AsciiVSPrint ( The ASCII string is produced by parsing the format string specified by FormatString. Arguments are pulled from the variable argument list based on the contents of the format string. - The length of the produced output buffer is returned. + The number of ASCII characters in the produced output buffer is returned not including + the Null-terminator. If BufferSize is 0, then no output buffer is produced and 0 is returned. - If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize is not 0 and FormatString is NULL, then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than - PcdMaximumUnicodeStringLength ASCII characters, then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string - contains more than PcdMaximumUnicodeStringLength ASCII characters, then ASSERT(). + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). + If BufferSize > 0 and FormatString is NULL, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than + PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then + ASSERT(). + If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string + contains more than PcdMaximumAsciiStringLength ASCII characters not including the + Null-terminator, then ASSERT(). - @param StartOfBuffer APointer to the output buffer for the produced Null-terminated + @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. @param FormatString Null-terminated Unicode format string. - @return Length of the produced output buffer. + @return The number of ASCII characters in the produced output buffer not including the + Null-terminator. **/ UINTN @@ -811,23 +877,27 @@ AsciiSPrint ( The ASCII string is produced by parsing the format string specified by FormatString. Arguments are pulled from the variable argument list specified by Marker based on the contents of the format string. - The length of the produced output buffer is returned. + The number of ASCII characters in the produced output buffer is returned not including + the Null-terminator. If BufferSize is 0, then no output buffer is produced and 0 is returned. - If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize is not 0 and FormatString is NULL, then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than - PcdMaximumUnicodeStringLength ASCII characters, then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string - contains more than PcdMaximumUnicodeStringLength ASCII characters, then ASSERT(). + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). + If BufferSize > 0 and FormatString is NULL, then ASSERT(). + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than + PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then + ASSERT(). + If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string + contains more than PcdMaximumAsciiStringLength ASCII characters not including the + Null-terminator, then ASSERT(). - @param StartOfBuffer APointer to the output buffer for the produced Null-terminated + @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. @param FormatString Null-terminated Unicode format string. @param Marker VA_LIST marker for the variable argument list. - @return Length of the produced output buffer. + @return The number of ASCII characters in the produced output buffer not including the + Null-terminator. **/ UINTN @@ -851,22 +921,26 @@ AsciiVSPrintUnicodeFormat ( The ASCII string is produced by parsing the format string specified by FormatString. Arguments are pulled from the variable argument list based on the contents of the format string. - The length of the produced output buffer is returned. + The number of ASCII characters in the produced output buffer is returned not including + the Null-terminator. If BufferSize is 0, then no output buffer is produced and 0 is returned. - If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize is not 0 and FormatString is NULL, then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than - PcdMaximumUnicodeStringLength ASCII characters, then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string - contains more than PcdMaximumUnicodeStringLength ASCII characters, then ASSERT(). + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). + If BufferSize > 0 and FormatString is NULL, then ASSERT(). + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than + PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then + ASSERT(). + If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string + contains more than PcdMaximumAsciiStringLength ASCII characters not including the + Null-terminator, then ASSERT(). - @param StartOfBuffer APointer to the output buffer for the produced Null-terminated + @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. @param FormatString Null-terminated Unicode format string. - @return Length of the produced output buffer. + @return The number of ASCII characters in the produced output buffer not including the + Null-terminator. **/ UINTN @@ -890,7 +964,7 @@ AsciiSPrintUnicodeFormat ( Converts the decimal number specified by Value to a Null-terminated Unicode string specified by Buffer containing at most Width characters. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed. - The total number of characters placed in Buffer is returned. + The number of Unicode characters in Buffer is returned not including the Null-terminator. If the conversion contains more than Width characters, then only the first Width characters are returned, and the total number of characters required to perform the conversion is returned. @@ -914,9 +988,10 @@ AsciiSPrintUnicodeFormat ( Unicode string. @param Flags The bitmask of flags that specify left justification, zero pad, and commas. @param Value The 64-bit signed value to convert to a string. - @param Width The maximum number of Unicode characters to place in Buffer. + @param Width The maximum number of Unicode characters to place in Buffer, not including + the Null-terminator. - @return Total number of characters required to perform the conversion. + @return The number of Unicode characters in Buffer not including the Null-terminator. **/ UINTN @@ -937,7 +1012,7 @@ UnicodeValueToString ( Converts the decimal number specified by Value to a Null-terminated ASCII string specified by Buffer containing at most Width characters. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed. - The total number of characters placed in Buffer is returned. + The number of ASCII characters in Buffer is returned not including the Null-terminator. If the conversion contains more than Width characters, then only the first Width characters are returned, and the total number of characters required to perform the conversion is returned. @@ -961,9 +1036,10 @@ UnicodeValueToString ( ASCII string. @param Flags The bitmask of flags that specify left justification, zero pad, and commas. @param Value The 64-bit signed value to convert to a string. - @param Width The maximum number of ASCII characters to place in Buffer. + @param Width The maximum number of ASCII characters to place in Buffer, not including + the Null-terminator. - @return Total number of characters required to perform the conversion. + @return The number of ASCII characters in Buffer not including the Null-terminator. **/ UINTN