mirror of https://github.com/acidanthera/audk.git
MdeModulePkg DxePrintLibPrint2Protocol Library SPrintLength() API issue.
SPrintLength() and SPrintLengthAsciiFormat() API doesn’t work with 'g', 't' and 'r' option. The fix sync from MdePkg BasePrintLib instance. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Eric Dong <eric.dong@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16593 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
c792e5b8a3
commit
586d81d103
|
@ -6,7 +6,7 @@
|
|||
protocol related to this implementation, not in the public spec. So, this
|
||||
library instance is only for this code base.
|
||||
|
||||
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
|
@ -1076,8 +1076,8 @@ InternalPrintLibSPrint (
|
|||
return NumberOfPrinted;
|
||||
}
|
||||
|
||||
#define WARNING_STATUS_NUMBER 4
|
||||
#define ERROR_STATUS_NUMBER 24
|
||||
#define WARNING_STATUS_NUMBER 5
|
||||
#define ERROR_STATUS_NUMBER 33
|
||||
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mStatusString[] = {
|
||||
"Success", // RETURN_SUCCESS = 0
|
||||
|
@ -1085,6 +1085,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mStatusString[] = {
|
|||
"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
|
||||
"Warning Stale Data", // RETURN_WARN_STALE_DATA = 5
|
||||
"Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT
|
||||
"Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT
|
||||
"Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT
|
||||
|
@ -1108,9 +1109,56 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mStatusString[] = {
|
|||
"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
|
||||
"Protocol Error", // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT
|
||||
"Incompatible Version", // RETURN_INCOMPATIBLE_VERSION = 25 | MAX_BIT
|
||||
"Security Violation", // RETURN_SECURITY_VIOLATION = 26 | MAX_BIT
|
||||
"CRC Error", // RETURN_CRC_ERROR = 27 | MAX_BIT
|
||||
"End of Media", // RETURN_END_OF_MEDIA = 28 | MAX_BIT
|
||||
"Reserved (29)", // RESERVED = 29 | MAX_BIT
|
||||
"Reserved (30)", // RESERVED = 30 | MAX_BIT
|
||||
"End of File", // RETURN_END_OF_FILE = 31 | MAX_BIT
|
||||
"Invalid Language", // RETURN_INVALID_LANGUAGE = 32 | MAX_BIT
|
||||
"Compromised Data" // RETURN_COMPROMISED_DATA = 33 | MAX_BIT
|
||||
};
|
||||
|
||||
/**
|
||||
Internal function that places the character into the Buffer.
|
||||
|
||||
Internal function that places ASCII or Unicode character into the Buffer.
|
||||
|
||||
@param Buffer The buffer to place the Unicode or ASCII string.
|
||||
@param EndBuffer The end of the input Buffer. No characters will be
|
||||
placed after that.
|
||||
@param Length The count of character to be placed into Buffer.
|
||||
(Negative value indicates no buffer fill.)
|
||||
@param Character The character to be placed into Buffer.
|
||||
@param Increment The character increment in Buffer.
|
||||
|
||||
@return Buffer.
|
||||
|
||||
**/
|
||||
CHAR8 *
|
||||
InternalPrintLibFillBuffer (
|
||||
OUT CHAR8 *Buffer,
|
||||
IN CHAR8 *EndBuffer,
|
||||
IN INTN Length,
|
||||
IN UINTN Character,
|
||||
IN INTN Increment
|
||||
)
|
||||
{
|
||||
INTN Index;
|
||||
|
||||
for (Index = 0; Index < Length && Buffer < EndBuffer; Index++) {
|
||||
*Buffer = (CHAR8) Character;
|
||||
if (Increment != 1) {
|
||||
*(Buffer + 1) = (CHAR8)(Character >> 8);
|
||||
}
|
||||
Buffer += Increment;
|
||||
}
|
||||
|
||||
return Buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
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.
|
||||
|
@ -1149,6 +1197,7 @@ InternalPrintLibSPrintMarker (
|
|||
IN BASE_LIST BaseListMarker OPTIONAL
|
||||
)
|
||||
{
|
||||
CHAR8 *OriginalBuffer;
|
||||
CHAR8 *EndBuffer;
|
||||
CHAR8 ValueBuffer[MAXIMUM_VALUE_CHARACTERS];
|
||||
UINT32 BytesPerOutputCharacter;
|
||||
|
@ -1185,7 +1234,19 @@ InternalPrintLibSPrintMarker (
|
|||
// DxePrintLibPrint2Protocol (both PrintLib instances).
|
||||
//
|
||||
|
||||
ASSERT(Flags & COUNT_ONLY_NO_PRINT);
|
||||
if ((Flags & COUNT_ONLY_NO_PRINT) != 0) {
|
||||
if (BufferSize == 0) {
|
||||
Buffer = NULL;
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// We can run without a Buffer for counting only.
|
||||
//
|
||||
if (BufferSize == 0) {
|
||||
return 0;
|
||||
}
|
||||
ASSERT (Buffer != NULL);
|
||||
}
|
||||
|
||||
if ((Flags & OUTPUT_UNICODE) != 0) {
|
||||
BytesPerOutputCharacter = 2;
|
||||
|
@ -1194,16 +1255,21 @@ InternalPrintLibSPrintMarker (
|
|||
}
|
||||
|
||||
LengthToReturn = 0;
|
||||
EndBuffer = NULL;
|
||||
OriginalBuffer = NULL;
|
||||
|
||||
//
|
||||
// Reserve space for the Null terminator.
|
||||
//
|
||||
BufferSize--;
|
||||
if (Buffer != NULL) {
|
||||
BufferSize--;
|
||||
OriginalBuffer = Buffer;
|
||||
|
||||
//
|
||||
// Set the tag for the end of the input Buffer.
|
||||
//
|
||||
EndBuffer = Buffer + BufferSize * BytesPerOutputCharacter;
|
||||
//
|
||||
// Set the tag for the end of the input Buffer.
|
||||
//
|
||||
EndBuffer = Buffer + BufferSize * BytesPerOutputCharacter;
|
||||
}
|
||||
|
||||
if ((Flags & FORMAT_UNICODE) != 0) {
|
||||
//
|
||||
|
@ -1231,11 +1297,14 @@ InternalPrintLibSPrintMarker (
|
|||
//
|
||||
// Loop until the end of the format string is reached or the output buffer is full
|
||||
//
|
||||
while (FormatCharacter != 0 && Buffer < EndBuffer) {
|
||||
while (FormatCharacter != 0) {
|
||||
if ((Buffer != NULL) && (Buffer >= EndBuffer)) {
|
||||
break;
|
||||
}
|
||||
//
|
||||
// Clear all the flag bits except those that may have been passed in
|
||||
//
|
||||
Flags &= (UINTN)(OUTPUT_UNICODE | FORMAT_UNICODE | COUNT_ONLY_NO_PRINT);
|
||||
Flags &= (UINTN) (OUTPUT_UNICODE | FORMAT_UNICODE | COUNT_ONLY_NO_PRINT);
|
||||
|
||||
//
|
||||
// Set the default width to zero, and the default precision to 1
|
||||
|
@ -1343,10 +1412,13 @@ InternalPrintLibSPrintMarker (
|
|||
//
|
||||
// Flag space, +, 0, L & l are invalid for type p.
|
||||
//
|
||||
Flags &= ~(UINTN)(PREFIX_BLANK | PREFIX_SIGN | PREFIX_ZERO | LONG_TYPE);
|
||||
Flags &= ~((UINTN) (PREFIX_BLANK | PREFIX_SIGN | PREFIX_ZERO | LONG_TYPE));
|
||||
if (sizeof (VOID *) > 4) {
|
||||
Flags |= LONG_TYPE;
|
||||
}
|
||||
//
|
||||
// break skipped on purpose
|
||||
//
|
||||
case 'X':
|
||||
Flags |= PREFIX_ZERO;
|
||||
//
|
||||
|
@ -1391,7 +1463,7 @@ InternalPrintLibSPrintMarker (
|
|||
if ((Flags & RADIX_HEX) == 0) {
|
||||
Radix = 10;
|
||||
if (Comma) {
|
||||
Flags &= (~(UINTN)PREFIX_ZERO);
|
||||
Flags &= ~((UINTN) PREFIX_ZERO);
|
||||
Precision = 1;
|
||||
}
|
||||
if (Value < 0) {
|
||||
|
@ -1673,17 +1745,32 @@ InternalPrintLibSPrintMarker (
|
|||
//
|
||||
if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {
|
||||
LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);
|
||||
if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
|
||||
Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);
|
||||
}
|
||||
}
|
||||
|
||||
if (ZeroPad) {
|
||||
if (Prefix != 0) {
|
||||
LengthToReturn += (1 * BytesPerOutputCharacter);
|
||||
if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
|
||||
Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);
|
||||
}
|
||||
}
|
||||
LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);
|
||||
if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
|
||||
Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, '0', BytesPerOutputCharacter);
|
||||
}
|
||||
} else {
|
||||
LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);
|
||||
if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
|
||||
Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, ' ', BytesPerOutputCharacter);
|
||||
}
|
||||
if (Prefix != 0) {
|
||||
LengthToReturn += (1 * BytesPerOutputCharacter);
|
||||
if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
|
||||
Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1702,6 +1789,9 @@ InternalPrintLibSPrintMarker (
|
|||
ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask;
|
||||
|
||||
LengthToReturn += (1 * BytesPerOutputCharacter);
|
||||
if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
|
||||
Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, ArgumentCharacter, BytesPerOutputCharacter);
|
||||
}
|
||||
ArgumentString += BytesPerArgumentCharacter;
|
||||
Index++;
|
||||
if (Comma) {
|
||||
|
@ -1711,6 +1801,9 @@ InternalPrintLibSPrintMarker (
|
|||
Index++;
|
||||
if (Index < Count) {
|
||||
LengthToReturn += (1 * BytesPerOutputCharacter);
|
||||
if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
|
||||
Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, ',', BytesPerOutputCharacter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1721,6 +1814,9 @@ InternalPrintLibSPrintMarker (
|
|||
//
|
||||
if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) {
|
||||
LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);
|
||||
if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
|
||||
Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -1734,7 +1830,27 @@ InternalPrintLibSPrintMarker (
|
|||
FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
|
||||
}
|
||||
|
||||
return (LengthToReturn / BytesPerOutputCharacter);
|
||||
if ((Flags & COUNT_ONLY_NO_PRINT) != 0) {
|
||||
return (LengthToReturn / BytesPerOutputCharacter);
|
||||
}
|
||||
|
||||
ASSERT (Buffer != NULL);
|
||||
//
|
||||
// Null terminate the Unicode or ASCII string
|
||||
//
|
||||
InternalPrintLibFillBuffer (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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue