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:
qhuang8 2008-02-01 15:02:05 +00:00
parent 8fd567c6f1
commit 4df26661c7

View File

@ -434,8 +434,8 @@ StrnCat (
or String contains more than PcdMaximumUnicodeStringLength Unicode or String contains more than PcdMaximumUnicodeStringLength Unicode
characters not including the Null-terminator, then ASSERT(). characters not including the Null-terminator, then ASSERT().
@param String Pointer to a Null-terminated Unicode string. @param String Pointer to a Null-terminated Unicode string.
@param SearchString Pointer to a Null-terminated Unicode string to search for. @param SearchString Pointer to a Null-terminated Unicode string to search for.
@retval NULL If the SearchString does not appear in String. @retval NULL If the SearchString does not appear in String.
@retval !NULL If there is a match. @retval !NULL If there is a match.
@ -444,33 +444,19 @@ StrnCat (
CHAR16 * CHAR16 *
EFIAPI EFIAPI
StrStr ( StrStr (
IN CONST CHAR16 *String, IN CONST CHAR16 *String,
IN CONST CHAR16 *SearchString IN CONST CHAR16 *SearchString
) )
{ {
CONST CHAR16 *FirstMatch; CONST CHAR16 *FirstMatch;
CONST CHAR16 *SearchStringTmp; CONST CHAR16 *SearchStringTmp;
ASSERT (String != NULL);
ASSERT (((UINTN) String & 0x01) == 0);
ASSERT (SearchString != NULL);
ASSERT (((UINTN) SearchString & 0x01) == 0);
// //
// If PcdMaximumUnicodeStringLength is not zero, // ASSERT both strings are less long than PcdMaximumUnicodeStringLength.
// length of String should not more than PcdMaximumUnicodeStringLength // Length tests are performed inside StrLen().
// //
if (PcdGet32 (PcdMaximumUnicodeStringLength) != 0) { ASSERT (StrSize (String) != 0);
ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength)); ASSERT (StrSize (SearchString) != 0);
}
//
// If PcdMaximumUnicodeStringLength is not zero,
// length of SearchString should not more than PcdMaximumUnicodeStringLength
//
if (PcdGet32 (PcdMaximumUnicodeStringLength) != 0) {
ASSERT (StrLen (SearchString) < PcdGet32 (PcdMaximumAsciiStringLength));
}
while (*String != '\0') { while (*String != '\0') {
SearchStringTmp = SearchString; SearchStringTmp = SearchString;
@ -633,7 +619,7 @@ InternalIsHexaDecimalDigitCharacter (
more than PcdMaximumUnicodeStringLength Unicode characters not including more than PcdMaximumUnicodeStringLength Unicode characters not including
the Null-terminator, then ASSERT(). the Null-terminator, then ASSERT().
@param String Pointer to a Null-terminated Unicode string. @param String Pointer to a Null-terminated Unicode string.
@retval UINTN @retval UINTN
@ -641,14 +627,16 @@ InternalIsHexaDecimalDigitCharacter (
UINTN UINTN
EFIAPI EFIAPI
StrDecimalToUintn ( StrDecimalToUintn (
IN CONST CHAR16 *String IN CONST CHAR16 *String
) )
{ {
UINTN Result; UINTN Result;
ASSERT (String != NULL); //
ASSERT (((UINTN) String & 0x01) == 0); // ASSERT String is less long than PcdMaximumUnicodeStringLength.
ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength)); // Length tests are performed inside StrLen().
//
ASSERT (StrSize (String) != 0);
// //
// Ignore the pad spaces (space or tab) // Ignore the pad spaces (space or tab)
@ -713,7 +701,7 @@ StrDecimalToUintn (
more than PcdMaximumUnicodeStringLength Unicode characters not including more than PcdMaximumUnicodeStringLength Unicode characters not including
the Null-terminator, then ASSERT(). the Null-terminator, then ASSERT().
@param String Pointer to a Null-terminated Unicode string. @param String Pointer to a Null-terminated Unicode string.
@retval UINT64 @retval UINT64
@ -721,14 +709,16 @@ StrDecimalToUintn (
UINT64 UINT64
EFIAPI EFIAPI
StrDecimalToUint64 ( StrDecimalToUint64 (
IN CONST CHAR16 *String IN CONST CHAR16 *String
) )
{ {
UINT64 Result; UINT64 Result;
ASSERT (String != NULL); //
ASSERT (((UINTN) String & 0x01) == 0); // ASSERT String is less long than PcdMaximumUnicodeStringLength.
ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength)); // Length tests are performed inside StrLen().
//
ASSERT (StrSize (String) != 0);
// //
// Ignore the pad spaces (space or tab) // Ignore the pad spaces (space or tab)
@ -793,7 +783,7 @@ StrDecimalToUint64 (
PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
then ASSERT(). then ASSERT().
@param String Pointer to a Null-terminated Unicode string. @param String Pointer to a Null-terminated Unicode string.
@retval UINTN @retval UINTN
@ -801,14 +791,16 @@ StrDecimalToUint64 (
UINTN UINTN
EFIAPI EFIAPI
StrHexToUintn ( StrHexToUintn (
IN CONST CHAR16 *String IN CONST CHAR16 *String
) )
{ {
UINTN Result; UINTN Result;
ASSERT (String != NULL); //
ASSERT (((UINTN) String & 0x01) == 0); // ASSERT String is less long than PcdMaximumUnicodeStringLength.
ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength)); // Length tests are performed inside StrLen().
//
ASSERT (StrSize (String) != 0);
// //
// Ignore the pad spaces (space or tab) // Ignore the pad spaces (space or tab)
@ -885,7 +877,7 @@ StrHexToUintn (
PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
then ASSERT(). then ASSERT().
@param String Pointer to a Null-terminated Unicode string. @param String Pointer to a Null-terminated Unicode string.
@retval UINT64 @retval UINT64
@ -893,14 +885,16 @@ StrHexToUintn (
UINT64 UINT64
EFIAPI EFIAPI
StrHexToUint64 ( StrHexToUint64 (
IN CONST CHAR16 *String IN CONST CHAR16 *String
) )
{ {
UINT64 Result; UINT64 Result;
ASSERT (String != NULL); //
ASSERT (((UINTN) String & 0x01) == 0); // ASSERT String is less long than PcdMaximumUnicodeStringLength.
ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength)); // Length tests are performed inside StrLen().
//
ASSERT (StrSize (String) != 0);
// //
// Ignore the pad spaces (space or tab) // Ignore the pad spaces (space or tab)
@ -1031,13 +1025,19 @@ InternalAsciiIsHexaDecimalDigitCharacter (
CHAR8 * CHAR8 *
EFIAPI EFIAPI
UnicodeStrToAsciiStr ( UnicodeStrToAsciiStr (
IN CONST CHAR16 *Source, IN CONST CHAR16 *Source,
OUT CHAR8 *Destination OUT CHAR8 *Destination
) )
{ {
CHAR8 *ReturnValue;
ASSERT (Destination != NULL); 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 // Source and Destination should not overlap
@ -1045,14 +1045,8 @@ UnicodeStrToAsciiStr (
ASSERT ((UINTN) ((CHAR16 *) Destination - Source) > StrLen (Source)); ASSERT ((UINTN) ((CHAR16 *) Destination - Source) > StrLen (Source));
ASSERT ((UINTN) ((CHAR8 *) Source - Destination) > 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') { while (*Source != '\0') {
// //
// If any Unicode characters in Source contain // If any Unicode characters in Source contain
@ -1063,8 +1057,14 @@ UnicodeStrToAsciiStr (
} }
*Destination = '\0'; *Destination = '\0';
return Destination; //
// ASSERT Original Destination is less long than PcdMaximumAsciiStringLength.
// Length tests are performed inside AsciiStrLen().
//
ASSERT (AsciiStrSize (ReturnValue) != 0);
return ReturnValue;
} }
@ -1563,8 +1563,8 @@ AsciiStrnCat (
String contains more than PcdMaximumAsciiStringLength Unicode characters String contains more than PcdMaximumAsciiStringLength Unicode characters
not including the Null-terminator, then ASSERT(). not including the Null-terminator, then ASSERT().
@param String Pointer to a Null-terminated ASCII string. @param String Pointer to a Null-terminated ASCII string.
@param SearchString Pointer to a Null-terminated ASCII string to search for. @param SearchString Pointer to a Null-terminated ASCII string to search for.
@retval NULL If the SearchString does not appear in String. @retval NULL If the SearchString does not appear in String.
@retval !NULL If there is a match. @retval !NULL If there is a match.
@ -1573,31 +1573,18 @@ AsciiStrnCat (
CHAR8 * CHAR8 *
EFIAPI EFIAPI
AsciiStrStr ( AsciiStrStr (
IN CONST CHAR8 *String, IN CONST CHAR8 *String,
IN CONST CHAR8 *SearchString IN CONST CHAR8 *SearchString
) )
{ {
CONST CHAR8 *FirstMatch; CONST CHAR8 *FirstMatch;
CONST CHAR8 *SearchStringTmp; CONST CHAR8 *SearchStringTmp;
ASSERT (String != NULL);
ASSERT (SearchString != NULL);
// //
// If PcdMaximumUnicodeStringLength is not zero, // ASSERT both strings are less long than PcdMaximumAsciiStringLength
// length of String should not more than PcdMaximumUnicodeStringLength
// //
if (PcdGet32 (PcdMaximumAsciiStringLength) != 0) { ASSERT (AsciiStrSize (String) != 0);
ASSERT (AsciiStrLen (String) < PcdGet32 (PcdMaximumAsciiStringLength)); ASSERT (AsciiStrSize (SearchString) != 0);
}
//
// If PcdMaximumUnicodeStringLength is not zero,
// length of SearchString should not more than PcdMaximumUnicodeStringLength
//
if (PcdGet32 (PcdMaximumAsciiStringLength) != 0) {
ASSERT (AsciiStrLen (SearchString) < PcdGet32 (PcdMaximumAsciiStringLength));
}
while (*String != '\0') { while (*String != '\0') {
SearchStringTmp = SearchString; SearchStringTmp = SearchString;
@ -1653,7 +1640,7 @@ AsciiStrStr (
PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
then ASSERT(). then ASSERT().
@param String Pointer to a Null-terminated ASCII string. @param String Pointer to a Null-terminated ASCII string.
@retval UINTN @retval UINTN
@ -1661,13 +1648,15 @@ AsciiStrStr (
UINTN UINTN
EFIAPI EFIAPI
AsciiStrDecimalToUintn ( AsciiStrDecimalToUintn (
IN CONST CHAR8 *String IN CONST CHAR8 *String
) )
{ {
UINTN Result; 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) // Ignore the pad spaces (space or tab)
@ -1728,7 +1717,7 @@ AsciiStrDecimalToUintn (
PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
then ASSERT(). then ASSERT().
@param String Pointer to a Null-terminated ASCII string. @param String Pointer to a Null-terminated ASCII string.
@retval UINT64 @retval UINT64
@ -1736,13 +1725,15 @@ AsciiStrDecimalToUintn (
UINT64 UINT64
EFIAPI EFIAPI
AsciiStrDecimalToUint64 ( AsciiStrDecimalToUint64 (
IN CONST CHAR8 *String IN CONST CHAR8 *String
) )
{ {
UINT64 Result; 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) // Ignore the pad spaces (space or tab)
@ -1806,7 +1797,7 @@ AsciiStrDecimalToUint64 (
and String contains more than PcdMaximumAsciiStringLength ASCII characters not including and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
the Null-terminator, then ASSERT(). the Null-terminator, then ASSERT().
@param String Pointer to a Null-terminated ASCII string. @param String Pointer to a Null-terminated ASCII string.
@retval UINTN @retval UINTN
@ -1814,13 +1805,15 @@ AsciiStrDecimalToUint64 (
UINTN UINTN
EFIAPI EFIAPI
AsciiStrHexToUintn ( AsciiStrHexToUintn (
IN CONST CHAR8 *String IN CONST CHAR8 *String
) )
{ {
UINTN Result; 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) // Ignore the pad spaces (space or tab)
@ -1896,7 +1889,7 @@ AsciiStrHexToUintn (
and String contains more than PcdMaximumAsciiStringLength ASCII characters not including and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
the Null-terminator, then ASSERT(). the Null-terminator, then ASSERT().
@param String Pointer to a Null-terminated ASCII string. @param String Pointer to a Null-terminated ASCII string.
@retval UINT64 @retval UINT64
@ -1904,13 +1897,15 @@ AsciiStrHexToUintn (
UINT64 UINT64
EFIAPI EFIAPI
AsciiStrHexToUint64 ( AsciiStrHexToUint64 (
IN CONST CHAR8 *String IN CONST CHAR8 *String
) )
{ {
UINT64 Result; 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 // Ignore the pad spaces (space or tab) and leading Zeros
@ -1991,12 +1986,18 @@ AsciiStrHexToUint64 (
CHAR16 * CHAR16 *
EFIAPI EFIAPI
AsciiStrToUnicodeStr ( AsciiStrToUnicodeStr (
IN CONST CHAR8 *Source, IN CONST CHAR8 *Source,
OUT CHAR16 *Destination OUT CHAR16 *Destination
) )
{ {
CHAR16 *ReturnValue;
ASSERT (Destination != NULL); ASSERT (Destination != NULL);
ASSERT (Source != NULL);
//
// ASSERT Source is less long than PcdMaximumAsciiStringLength
//
ASSERT (AsciiStrSize (Source) != 0);
// //
// Source and Destination should not overlap // Source and Destination should not overlap
@ -2004,14 +2005,8 @@ AsciiStrToUnicodeStr (
ASSERT ((UINTN) ((CHAR8 *) Destination - Source) > AsciiStrLen (Source)); ASSERT ((UINTN) ((CHAR8 *) Destination - Source) > AsciiStrLen (Source));
ASSERT ((UINTN) (Source - (CHAR8 *) Destination) > (AsciiStrLen (Source) * sizeof (CHAR16))); ASSERT ((UINTN) (Source - (CHAR8 *) Destination) > (AsciiStrLen (Source) * sizeof (CHAR16)));
//
// If PcdMaximumAsciiStringLength is not zero, ReturnValue = Destination;
// length of Source should not more than PcdMaximumUnicodeStringLength
//
if (PcdGet32 (PcdMaximumAsciiStringLength) != 0) {
ASSERT (AsciiStrLen (Source) < PcdGet32 (PcdMaximumAsciiStringLength));
}
while (*Source != '\0') { while (*Source != '\0') {
*(Destination++) = (CHAR16) *(Source++); *(Destination++) = (CHAR16) *(Source++);
} }
@ -2020,7 +2015,12 @@ AsciiStrToUnicodeStr (
// //
*Destination = '\0'; *Destination = '\0';
return Destination; //
// ASSERT Original Destination is less long than PcdMaximumUnicodeStringLength
//
ASSERT (StrSize (ReturnValue) != 0);
return ReturnValue;
} }
/** /**