OcStringLib: Fix safe SPrint va_arg usage

This commit is contained in:
vit9696 2020-03-14 04:57:26 +03:00
parent c25f05f9df
commit 641f72e7f3
2 changed files with 16 additions and 2 deletions

View File

@ -142,6 +142,7 @@ OcAsciiSafeSPrint (
{
EFI_STATUS Status;
VA_LIST Marker;
VA_LIST Marker2;
UINTN NumberOfPrinted;
ASSERT (StartOfBuffer != NULL);
@ -149,13 +150,19 @@ OcAsciiSafeSPrint (
ASSERT (FormatString != NULL);
VA_START (Marker, FormatString);
NumberOfPrinted = SPrintLengthAsciiFormat (FormatString, Marker);
VA_COPY (Marker2, Marker);
NumberOfPrinted = SPrintLengthAsciiFormat (FormatString, Marker2);
VA_END (Marker2);
if (BufferSize - 1 >= NumberOfPrinted) {
AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
Status = EFI_SUCCESS;
} else {
Status = EFI_OUT_OF_RESOURCES;
}
VA_END (Marker);
return Status;
}

View File

@ -187,6 +187,7 @@ OcUnicodeSafeSPrint (
{
EFI_STATUS Status;
VA_LIST Marker;
VA_LIST Marker2;
UINTN NumberOfPrinted;
ASSERT (StartOfBuffer != NULL);
@ -194,13 +195,19 @@ OcUnicodeSafeSPrint (
ASSERT (FormatString != NULL);
VA_START (Marker, FormatString);
NumberOfPrinted = SPrintLength (FormatString, Marker);
VA_COPY (Marker2, Marker);
NumberOfPrinted = SPrintLength (FormatString, Marker2);
VA_END (Marker2);
if (BufferSize - 1 >= NumberOfPrinted) {
UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
Status = EFI_SUCCESS;
} else {
Status = EFI_OUT_OF_RESOURCES;
}
VA_END (Marker);
return Status;
}