\r
#include "PrintLibInternal.h"\r
\r
-typedef struct {\r
- RETURN_STATUS Status;\r
- CHAR8 *String;\r
-} STATUS_LOOKUP_TABLE_ENTRY;\r
-\r
-static CONST STATUS_LOOKUP_TABLE_ENTRY StatusString[] = {\r
- { RETURN_SUCCESS, "Success" },\r
- { RETURN_LOAD_ERROR, "Load Error" },\r
- { RETURN_INVALID_PARAMETER, "Invalid Parameter" },\r
- { RETURN_UNSUPPORTED, "Unsupported" },\r
- { RETURN_BAD_BUFFER_SIZE, "Bad Buffer Size" },\r
- { RETURN_BUFFER_TOO_SMALL, "Buffer Too Small" },\r
- { RETURN_NOT_READY, "Not Ready" },\r
- { RETURN_DEVICE_ERROR, "Device Error" },\r
- { RETURN_WRITE_PROTECTED, "Write Protected" },\r
- { RETURN_OUT_OF_RESOURCES, "Out of Resources" },\r
- { RETURN_VOLUME_CORRUPTED, "Volume Corrupt" },\r
- { RETURN_VOLUME_FULL, "Volume Full" },\r
- { RETURN_NO_MEDIA, "No Media" },\r
- { RETURN_MEDIA_CHANGED, "Media changed" },\r
- { RETURN_NOT_FOUND, "Not Found" },\r
- { RETURN_ACCESS_DENIED, "Access Denied" },\r
- { RETURN_NO_RESPONSE, "No Response" },\r
- { RETURN_NO_MAPPING, "No mapping" },\r
- { RETURN_TIMEOUT, "Time out" },\r
- { RETURN_NOT_STARTED, "Not started" },\r
- { RETURN_ALREADY_STARTED, "Already started" },\r
- { RETURN_ABORTED, "Aborted" },\r
- { RETURN_ICMP_ERROR, "ICMP Error" },\r
- { RETURN_TFTP_ERROR, "TFTP Error" },\r
- { RETURN_PROTOCOL_ERROR, "Protocol Error" },\r
- { RETURN_WARN_UNKNOWN_GLYPH, "Warning Unknown Glyph" },\r
- { RETURN_WARN_DELETE_FAILURE, "Warning Delete Failure" },\r
- { RETURN_WARN_WRITE_FAILURE, "Warning Write Failure" },\r
- { RETURN_WARN_BUFFER_TOO_SMALL, "Warning Buffer Too Small" },\r
- { 0, NULL }\r
+#define WARNING_STATUS_NUMBER 4\r
+#define ERROR_STATUS_NUMBER 24\r
+\r
+STATIC 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
+ "Warning Write Failure", // RETURN_WARN_WRITE_FAILURE = 3\r
+ "Warning Buffer Too Small", // RETURN_WARN_BUFFER_TOO_SMALL = 4\r
+ "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT\r
+ "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT\r
+ "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT\r
+ "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT\r
+ "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT\r
+ "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT\r
+ "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT\r
+ "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT\r
+ "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT\r
+ "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT\r
+ "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT\r
+ "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT\r
+ "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT\r
+ "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT\r
+ "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT\r
+ "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT\r
+ "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT\r
+ "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT\r
+ "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT\r
+ "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT\r
+ "Aborted", // RETURN_ABORTED = 21 | MAX_BIT\r
+ "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT\r
+ "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT\r
+ "Protocol Error" // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT\r
};\r
\r
-\r
/**\r
Worker function that produces a Null-terminated string in an output buffer \r
based on a Null-terminated format string and a VA_LIST argument list.\r
@param Buffer Character buffer to print the results of the parsing\r
of Format into.\r
@param BufferSize Maximum number of characters to put into buffer.\r
- Zero means no limit.\r
@param Flags Intial flags value.\r
Can only have FORMAT_UNICODE and OUTPUT_UNICODE set\r
@param Format Null-terminated format string.\r
UINTN Width;\r
UINTN Precision;\r
INT64 Value;\r
- CHAR8 *ArgumentString;\r
+ CONST CHAR8 *ArgumentString;\r
UINTN Character;\r
GUID *TmpGuid;\r
TIME *TmpTime;\r
UINTN Radix;\r
RETURN_STATUS Status;\r
\r
+ if (BufferSize == 0) {\r
+ return 0;\r
+ }\r
ASSERT (Buffer != NULL);\r
- ASSERT (Format != NULL);\r
\r
OriginalBuffer = Buffer;\r
\r
BytesPerOutputCharacter = 1;\r
}\r
if ((Flags & FORMAT_UNICODE) != 0) {\r
+ //\r
+ // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength\r
+ // Unicode characters if PcdMaximumUnicodeStringLength is not zero. \r
+ //\r
+ ASSERT (StrSize ((CHAR16 *) Format) != 0);\r
BytesPerFormatCharacter = 2;\r
FormatMask = 0xffff;\r
} else {\r
+ //\r
+ // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength\r
+ // Ascii characters if PcdMaximumUnicodeStringLength is not zero. \r
+ //\r
+ ASSERT (AsciiStrSize (Format) != 0);\r
BytesPerFormatCharacter = 1;\r
FormatMask = 0xff;\r
}\r
\r
//\r
// Reserve space for the Null terminator.\r
- // If BufferSize is 0, this will set BufferSize to the max unsigned value\r
//\r
BufferSize--;\r
\r
} else {\r
BasePrintLibSPrint (\r
ValueBuffer,\r
- 0, \r
+ MAXIMUM_VALUE_CHARACTERS, \r
0,\r
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",\r
TmpGuid->Data1,\r
} else {\r
BasePrintLibSPrint (\r
ValueBuffer,\r
- 0,\r
+ MAXIMUM_VALUE_CHARACTERS,\r
0,\r
"%02d/%02d/%04d %02d:%02d",\r
TmpTime->Month,\r
case 'r':\r
Status = VA_ARG (Marker, RETURN_STATUS);\r
ArgumentString = ValueBuffer;\r
- for (Index = 0; StatusString[Index].String != NULL; Index++) {\r
- if (Status == StatusString[Index].Status) {\r
- ArgumentString = StatusString[Index].String;\r
+ if (RETURN_ERROR (Status)) {\r
+ //\r
+ // Clear error bit\r
+ //\r
+ Index = Status & ~MAX_BIT;\r
+ if (Index > 0 && Index <= ERROR_STATUS_NUMBER) {\r
+ ArgumentString = StatusString [Index + WARNING_STATUS_NUMBER];\r
+ }\r
+ } else {\r
+ Index = Status;\r
+ if (Index <= WARNING_STATUS_NUMBER) {\r
+ ArgumentString = StatusString [Index];\r
}\r
}\r
if (ArgumentString == ValueBuffer) {\r
- BasePrintLibSPrint ((CHAR8 *) ValueBuffer, 0, 0, "%08X", Status);\r
+ BasePrintLibSPrint ((CHAR8 *) ValueBuffer, MAXIMUM_VALUE_CHARACTERS, 0, "%08X", Status);\r
}\r
break;\r
\r
+ case '\n':\r
+ ArgumentString = "\n\r";\r
+ break;\r
+\r
case '%':\r
default:\r
//\r
break;\r
}\r
break;\r
+ \r
case '\n':\r
- ArgumentString = "\r\n";\r
+ ArgumentString = "\n\r";\r
break;\r
+\r
default:\r
ArgumentString = (CHAR8 *)&FormatCharacter;\r
Flags |= ARGUMENT_UNICODE;\r
// Null terminate the Unicode or ASCII string\r
//\r
Buffer = BasePrintLibFillBuffer (Buffer, 1, 0, BytesPerOutputCharacter);\r
+ //\r
+ // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength\r
+ // Unicode characters if PcdMaximumUnicodeStringLength is not zero. \r
+ //\r
+ ASSERT ((((Flags & OUTPUT_UNICODE) == 0)) || (StrSize ((CHAR16 *) OriginalBuffer) != 0));\r
+ //\r
+ // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength\r
+ // Ascii characters if PcdMaximumUnicodeStringLength is not zero. \r
+ //\r
+ ASSERT ((((Flags & OUTPUT_UNICODE) != 0)) || (AsciiStrSize (OriginalBuffer) != 0));\r
\r
+\r
return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter);\r
}\r
\r
VA_LIST Marker;\r
\r
VA_START (Marker, FormatString);\r
- return UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize >> 1, FormatString, Marker);\r
+ return UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
}\r
\r
/**\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.\r
\r
@return Total number of characters required to perform the conversion.\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.\r
\r
@return Total number of characters required to perform the conversion.\r
\r