audk/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c
Michael Kubacki 568eee7cf3 UnitTestFrameworkPkg/UnitTestResultReportLib: Use AsciiStrnCpyS()
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2721

The ReportOutput() function in UnitTestResultReportLib copies characters
from a function input buffer to an intermediate local buffer in fixed
size chunks of the maximum size of the intermediate buffer. The
implementation currently calls AsciiStrCpyS() which will ASSERT on an
error.

This commit changes the call to AsciiStrnCpyS() to avoid the
ASSERT which is not expected in the usage of the string copy in this
implementation.

Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Bret Barkelew <bret.barkelew@microsoft.com>
2020-05-27 02:28:22 +00:00

49 lines
1.1 KiB
C

/** @file
Implement UnitTestResultReportLib doing plain txt out to console
Copyright (c) Microsoft Corporation.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DebugLib.h>
VOID
ReportPrint (
IN CONST CHAR8 *Format,
...
)
{
VA_LIST Marker;
CHAR16 String[256];
UINTN Length;
VA_START (Marker, Format);
Length = UnicodeVSPrintAsciiFormat (String, sizeof (String), Format, Marker);
if (Length == 0) {
DEBUG ((DEBUG_ERROR, "%a formatted string is too long\n", __FUNCTION__));
} else {
gST->ConOut->OutputString (gST->ConOut, String);
}
VA_END (Marker);
}
VOID
ReportOutput (
IN CONST CHAR8 *Output
)
{
CHAR8 AsciiString[128];
UINTN Length;
UINTN Index;
Length = AsciiStrLen (Output);
for (Index = 0; Index < Length; Index += (sizeof (AsciiString) - 1)) {
AsciiStrnCpyS (AsciiString, sizeof (AsciiString), &Output[Index], sizeof (AsciiString) - 1);
ReportPrint ("%a", AsciiString);
}
}