#define WARNING_STATUS_NUMBER 4\r
#define ERROR_STATUS_NUMBER 24\r
\r
-STATIC CONST CHAR8 *StatusString [] = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *StatusString [] = {\r
"Success", // RETURN_SUCCESS = 0\r
"Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1\r
"Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE = 2\r
)\r
{\r
CHAR8 *OriginalBuffer;\r
+ CHAR8 *EndBuffer;\r
CHAR8 ValueBuffer[MAXIMUM_VALUE_CHARACTERS];\r
UINTN BytesPerOutputCharacter;\r
UINTN BytesPerFormatCharacter;\r
}\r
ASSERT (Buffer != NULL);\r
\r
- OriginalBuffer = Buffer;\r
-\r
if ((Flags & OUTPUT_UNICODE) != 0) {\r
BytesPerOutputCharacter = 2;\r
} else {\r
BytesPerOutputCharacter = 1;\r
}\r
+\r
+ //\r
+ // Reserve space for the Null terminator.\r
+ //\r
+ BufferSize--;\r
+ OriginalBuffer = Buffer;\r
+ //\r
+ // Set the tag for the end of the input Buffer.\r
+ //\r
+ EndBuffer = Buffer + BufferSize * BytesPerOutputCharacter;\r
+\r
if ((Flags & FORMAT_UNICODE) != 0) {\r
//\r
// Make sure format string cannot contain more than PcdMaximumUnicodeStringLength\r
FormatMask = 0xff;\r
}\r
\r
- //\r
- // Reserve space for the Null terminator.\r
- //\r
- BufferSize--;\r
+\r
\r
//\r
// Get the first character from the format string\r
//\r
// Loop until the end of the format string is reached or the output buffer is full\r
//\r
- while (FormatCharacter != 0 && BufferSize > 0) {\r
+ while (FormatCharacter != 0 && Buffer < EndBuffer) {\r
//\r
// Clear all the flag bits except those that may have been passed in\r
//\r
Format -= BytesPerFormatCharacter;\r
Precision = 0;\r
//\r
- // break skiped on purpose.\r
+ // break skipped on purpose.\r
//\r
default:\r
Done = TRUE;\r
}\r
} \r
\r
- //\r
- // Limit the maximum field width to the remaining characters in the output buffer\r
- //\r
- if (Width > BufferSize) {\r
- Width = BufferSize;\r
- }\r
-\r
//\r
// Handle each argument type\r
//\r
switch (FormatCharacter) {\r
case 'p':\r
+ //\r
+ // Flag space, +, 0, L & l are invalid for type p.\r
+ //\r
+ Flags &= ~(PREFIX_BLANK | PREFIX_SIGN | PREFIX_ZERO | LONG_TYPE);\r
if (sizeof (VOID *) > 4) {\r
Flags |= LONG_TYPE;\r
}\r
case 'X':\r
Flags |= PREFIX_ZERO;\r
//\r
- // break skiped on purpose\r
+ // break skipped on purpose\r
//\r
case 'x':\r
Flags |= RADIX_HEX;\r
//\r
- // break skiped on purpose\r
+ // break skipped on purpose\r
//\r
case 'd':\r
if ((Flags & LONG_TYPE) == 0) {\r
}\r
}\r
\r
- //\r
- // Limit the length of the string to append to the remaining characters in the output buffer\r
- //\r
- if (Count > BufferSize) {\r
- Count = BufferSize;\r
- }\r
if (Precision < Count) {\r
Precision = Count;\r
}\r
// Pad before the string\r
//\r
if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {\r
- Buffer = BasePrintLibFillBuffer (Buffer, Width - Precision, ' ', BytesPerOutputCharacter);\r
+ Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);\r
}\r
\r
if (ZeroPad) {\r
if (Prefix != 0) {\r
- Buffer = BasePrintLibFillBuffer (Buffer, 1, Prefix, BytesPerOutputCharacter);\r
+ Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);\r
}\r
- Buffer = BasePrintLibFillBuffer (Buffer, Precision - Count, '0', BytesPerOutputCharacter);\r
+ Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, '0', BytesPerOutputCharacter);\r
} else {\r
- Buffer = BasePrintLibFillBuffer (Buffer, Precision - Count, ' ', BytesPerOutputCharacter);\r
+ Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, ' ', BytesPerOutputCharacter);\r
if (Prefix != 0) {\r
- Buffer = BasePrintLibFillBuffer (Buffer, 1, Prefix, BytesPerOutputCharacter);\r
+ Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);\r
}\r
}\r
\r
while (Index < Count) {\r
ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask;\r
\r
- Buffer = BasePrintLibFillBuffer (Buffer, 1, ArgumentCharacter, BytesPerOutputCharacter);\r
+ Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ArgumentCharacter, BytesPerOutputCharacter);\r
ArgumentString += BytesPerArgumentCharacter;\r
Index++;\r
if (Comma) {\r
Digits = 0;\r
Index++;\r
if (Index < Count) {\r
- Buffer = BasePrintLibFillBuffer (Buffer, 1, ',', BytesPerOutputCharacter);\r
+ Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ',', BytesPerOutputCharacter);\r
}\r
}\r
}\r
// Pad after the string\r
//\r
if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) {\r
- Buffer = BasePrintLibFillBuffer (Buffer, Width - Precision, ' ', BytesPerOutputCharacter);\r
+ Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);\r
}\r
\r
- //\r
- // Reduce the number of characters\r
- //\r
- BufferSize -= Count;\r
-\r
//\r
// Get the next character from the format string\r
//\r
//\r
// Null terminate the Unicode or ASCII string\r
//\r
- BasePrintLibFillBuffer (Buffer, 1, 0, BytesPerOutputCharacter);\r
+ BasePrintLibFillBuffer (Buffer, EndBuffer + BytesPerOutputCharacter, 1, 0, BytesPerOutputCharacter);\r
//\r
// Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength\r
// Unicode characters if PcdMaximumUnicodeStringLength is not zero. \r
Unicode string.\r
@param Flags The bitmask of flags that specify left justification, zero pad, and commas.\r
@param Value The 64-bit signed value to convert to a string.\r
- @param Width The maximum number of Unicode characters to place in Buffer.\r
+ @param Width The maximum number of Unicode characters to place in Buffer, not including\r
+ the Null-terminator.\r
\r
@return The number of Unicode characters in Buffer not including the Null-terminator.\r
\r
ASCII string.\r
@param Flags The bitmask of flags that specify left justification, zero pad, and commas.\r
@param Value The 64-bit signed value to convert to a string.\r
- @param Width The maximum number of ASCII characters to place in Buffer.\r
+ @param Width The maximum number of ASCII characters to place in Buffer, not including\r
+ the Null-terminator.\r
\r
@return The number of ASCII characters in Buffer not including the Null-terminator.\r
\r