mirror of https://github.com/acidanthera/audk.git
1. Add conformance checking to ensure the input & output string are well-defined.
2. Adjust the return value of UnicodeStrToAsciiStr() & AsciiStrToUnicodeStr () to be the original destination string to follow MdeLib spec. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4653 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
8fd567c6f1
commit
4df26661c7
|
@ -451,26 +451,12 @@ StrStr (
|
|||
CONST CHAR16 *FirstMatch;
|
||||
CONST CHAR16 *SearchStringTmp;
|
||||
|
||||
ASSERT (String != NULL);
|
||||
ASSERT (((UINTN) String & 0x01) == 0);
|
||||
ASSERT (SearchString != NULL);
|
||||
ASSERT (((UINTN) SearchString & 0x01) == 0);
|
||||
|
||||
//
|
||||
// If PcdMaximumUnicodeStringLength is not zero,
|
||||
// length of String should not more than PcdMaximumUnicodeStringLength
|
||||
// ASSERT both strings are less long than PcdMaximumUnicodeStringLength.
|
||||
// Length tests are performed inside StrLen().
|
||||
//
|
||||
if (PcdGet32 (PcdMaximumUnicodeStringLength) != 0) {
|
||||
ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength));
|
||||
}
|
||||
|
||||
//
|
||||
// If PcdMaximumUnicodeStringLength is not zero,
|
||||
// length of SearchString should not more than PcdMaximumUnicodeStringLength
|
||||
//
|
||||
if (PcdGet32 (PcdMaximumUnicodeStringLength) != 0) {
|
||||
ASSERT (StrLen (SearchString) < PcdGet32 (PcdMaximumAsciiStringLength));
|
||||
}
|
||||
ASSERT (StrSize (String) != 0);
|
||||
ASSERT (StrSize (SearchString) != 0);
|
||||
|
||||
while (*String != '\0') {
|
||||
SearchStringTmp = SearchString;
|
||||
|
@ -646,9 +632,11 @@ StrDecimalToUintn (
|
|||
{
|
||||
UINTN Result;
|
||||
|
||||
ASSERT (String != NULL);
|
||||
ASSERT (((UINTN) String & 0x01) == 0);
|
||||
ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength));
|
||||
//
|
||||
// ASSERT String is less long than PcdMaximumUnicodeStringLength.
|
||||
// Length tests are performed inside StrLen().
|
||||
//
|
||||
ASSERT (StrSize (String) != 0);
|
||||
|
||||
//
|
||||
// Ignore the pad spaces (space or tab)
|
||||
|
@ -726,9 +714,11 @@ StrDecimalToUint64 (
|
|||
{
|
||||
UINT64 Result;
|
||||
|
||||
ASSERT (String != NULL);
|
||||
ASSERT (((UINTN) String & 0x01) == 0);
|
||||
ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength));
|
||||
//
|
||||
// ASSERT String is less long than PcdMaximumUnicodeStringLength.
|
||||
// Length tests are performed inside StrLen().
|
||||
//
|
||||
ASSERT (StrSize (String) != 0);
|
||||
|
||||
//
|
||||
// Ignore the pad spaces (space or tab)
|
||||
|
@ -806,9 +796,11 @@ StrHexToUintn (
|
|||
{
|
||||
UINTN Result;
|
||||
|
||||
ASSERT (String != NULL);
|
||||
ASSERT (((UINTN) String & 0x01) == 0);
|
||||
ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength));
|
||||
//
|
||||
// ASSERT String is less long than PcdMaximumUnicodeStringLength.
|
||||
// Length tests are performed inside StrLen().
|
||||
//
|
||||
ASSERT (StrSize (String) != 0);
|
||||
|
||||
//
|
||||
// Ignore the pad spaces (space or tab)
|
||||
|
@ -898,9 +890,11 @@ StrHexToUint64 (
|
|||
{
|
||||
UINT64 Result;
|
||||
|
||||
ASSERT (String != NULL);
|
||||
ASSERT (((UINTN) String & 0x01) == 0);
|
||||
ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength));
|
||||
//
|
||||
// ASSERT String is less long than PcdMaximumUnicodeStringLength.
|
||||
// Length tests are performed inside StrLen().
|
||||
//
|
||||
ASSERT (StrSize (String) != 0);
|
||||
|
||||
//
|
||||
// Ignore the pad spaces (space or tab)
|
||||
|
@ -1035,9 +1029,15 @@ UnicodeStrToAsciiStr (
|
|||
OUT CHAR8 *Destination
|
||||
)
|
||||
{
|
||||
CHAR8 *ReturnValue;
|
||||
|
||||
ASSERT (Destination != NULL);
|
||||
ASSERT (Source != NULL);
|
||||
ASSERT (((UINTN) Source & 0x01) == 0);
|
||||
|
||||
//
|
||||
// ASSERT if Source is long than PcdMaximumUnicodeStringLength.
|
||||
// Length tests are performed inside StrLen().
|
||||
//
|
||||
ASSERT (StrSize (Source) != 0);
|
||||
|
||||
//
|
||||
// Source and Destination should not overlap
|
||||
|
@ -1045,14 +1045,8 @@ UnicodeStrToAsciiStr (
|
|||
ASSERT ((UINTN) ((CHAR16 *) Destination - Source) > StrLen (Source));
|
||||
ASSERT ((UINTN) ((CHAR8 *) Source - Destination) > StrLen (Source));
|
||||
|
||||
//
|
||||
// If PcdMaximumUnicodeStringLength is not zero,
|
||||
// length of Source should not more than PcdMaximumUnicodeStringLength
|
||||
//
|
||||
if (PcdGet32 (PcdMaximumUnicodeStringLength) != 0) {
|
||||
ASSERT (StrLen (Source) < PcdGet32 (PcdMaximumUnicodeStringLength));
|
||||
}
|
||||
|
||||
ReturnValue = Destination;
|
||||
while (*Source != '\0') {
|
||||
//
|
||||
// If any Unicode characters in Source contain
|
||||
|
@ -1064,7 +1058,13 @@ UnicodeStrToAsciiStr (
|
|||
|
||||
*Destination = '\0';
|
||||
|
||||
return Destination;
|
||||
//
|
||||
// ASSERT Original Destination is less long than PcdMaximumAsciiStringLength.
|
||||
// Length tests are performed inside AsciiStrLen().
|
||||
//
|
||||
ASSERT (AsciiStrSize (ReturnValue) != 0);
|
||||
|
||||
return ReturnValue;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1580,24 +1580,11 @@ AsciiStrStr (
|
|||
CONST CHAR8 *FirstMatch;
|
||||
CONST CHAR8 *SearchStringTmp;
|
||||
|
||||
ASSERT (String != NULL);
|
||||
ASSERT (SearchString != NULL);
|
||||
|
||||
//
|
||||
// If PcdMaximumUnicodeStringLength is not zero,
|
||||
// length of String should not more than PcdMaximumUnicodeStringLength
|
||||
// ASSERT both strings are less long than PcdMaximumAsciiStringLength
|
||||
//
|
||||
if (PcdGet32 (PcdMaximumAsciiStringLength) != 0) {
|
||||
ASSERT (AsciiStrLen (String) < PcdGet32 (PcdMaximumAsciiStringLength));
|
||||
}
|
||||
|
||||
//
|
||||
// If PcdMaximumUnicodeStringLength is not zero,
|
||||
// length of SearchString should not more than PcdMaximumUnicodeStringLength
|
||||
//
|
||||
if (PcdGet32 (PcdMaximumAsciiStringLength) != 0) {
|
||||
ASSERT (AsciiStrLen (SearchString) < PcdGet32 (PcdMaximumAsciiStringLength));
|
||||
}
|
||||
ASSERT (AsciiStrSize (String) != 0);
|
||||
ASSERT (AsciiStrSize (SearchString) != 0);
|
||||
|
||||
while (*String != '\0') {
|
||||
SearchStringTmp = SearchString;
|
||||
|
@ -1666,8 +1653,10 @@ AsciiStrDecimalToUintn (
|
|||
{
|
||||
UINTN Result;
|
||||
|
||||
ASSERT (String != NULL);
|
||||
ASSERT (AsciiStrLen (String) < PcdGet32 (PcdMaximumAsciiStringLength));
|
||||
//
|
||||
// ASSERT Strings is less long than PcdMaximumAsciiStringLength
|
||||
//
|
||||
ASSERT (AsciiStrSize (String) != 0);
|
||||
|
||||
//
|
||||
// Ignore the pad spaces (space or tab)
|
||||
|
@ -1741,8 +1730,10 @@ AsciiStrDecimalToUint64 (
|
|||
{
|
||||
UINT64 Result;
|
||||
|
||||
ASSERT (String != NULL);
|
||||
ASSERT (AsciiStrLen (String) < PcdGet32 (PcdMaximumAsciiStringLength));
|
||||
//
|
||||
// ASSERT Strings is less long than PcdMaximumAsciiStringLength
|
||||
//
|
||||
ASSERT (AsciiStrSize (String) != 0);
|
||||
|
||||
//
|
||||
// Ignore the pad spaces (space or tab)
|
||||
|
@ -1819,8 +1810,10 @@ AsciiStrHexToUintn (
|
|||
{
|
||||
UINTN Result;
|
||||
|
||||
ASSERT (String != NULL);
|
||||
ASSERT (AsciiStrLen (String) < PcdGet32 (PcdMaximumAsciiStringLength));
|
||||
//
|
||||
// ASSERT Strings is less long than PcdMaximumAsciiStringLength
|
||||
//
|
||||
ASSERT (AsciiStrSize (String) != 0);
|
||||
|
||||
//
|
||||
// Ignore the pad spaces (space or tab)
|
||||
|
@ -1909,8 +1902,10 @@ AsciiStrHexToUint64 (
|
|||
{
|
||||
UINT64 Result;
|
||||
|
||||
ASSERT (String != NULL);
|
||||
ASSERT (AsciiStrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength));
|
||||
//
|
||||
// ASSERT Strings is less long than PcdMaximumAsciiStringLength
|
||||
//
|
||||
ASSERT (AsciiStrSize (String) != 0);
|
||||
|
||||
//
|
||||
// Ignore the pad spaces (space or tab) and leading Zeros
|
||||
|
@ -1995,8 +1990,14 @@ AsciiStrToUnicodeStr (
|
|||
OUT CHAR16 *Destination
|
||||
)
|
||||
{
|
||||
CHAR16 *ReturnValue;
|
||||
|
||||
ASSERT (Destination != NULL);
|
||||
ASSERT (Source != NULL);
|
||||
|
||||
//
|
||||
// ASSERT Source is less long than PcdMaximumAsciiStringLength
|
||||
//
|
||||
ASSERT (AsciiStrSize (Source) != 0);
|
||||
|
||||
//
|
||||
// Source and Destination should not overlap
|
||||
|
@ -2004,14 +2005,8 @@ AsciiStrToUnicodeStr (
|
|||
ASSERT ((UINTN) ((CHAR8 *) Destination - Source) > AsciiStrLen (Source));
|
||||
ASSERT ((UINTN) (Source - (CHAR8 *) Destination) > (AsciiStrLen (Source) * sizeof (CHAR16)));
|
||||
|
||||
//
|
||||
// If PcdMaximumAsciiStringLength is not zero,
|
||||
// length of Source should not more than PcdMaximumUnicodeStringLength
|
||||
//
|
||||
if (PcdGet32 (PcdMaximumAsciiStringLength) != 0) {
|
||||
ASSERT (AsciiStrLen (Source) < PcdGet32 (PcdMaximumAsciiStringLength));
|
||||
}
|
||||
|
||||
ReturnValue = Destination;
|
||||
while (*Source != '\0') {
|
||||
*(Destination++) = (CHAR16) *(Source++);
|
||||
}
|
||||
|
@ -2020,7 +2015,12 @@ AsciiStrToUnicodeStr (
|
|||
//
|
||||
*Destination = '\0';
|
||||
|
||||
return Destination;
|
||||
//
|
||||
// ASSERT Original Destination is less long than PcdMaximumUnicodeStringLength
|
||||
//
|
||||
ASSERT (StrSize (ReturnValue) != 0);
|
||||
|
||||
return ReturnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue