diff --git a/shared/source/program/print_formatter.cpp b/shared/source/program/print_formatter.cpp index bc8f64ed35..ac668bd8ee 100644 --- a/shared/source/program/print_formatter.cpp +++ b/shared/source/program/print_formatter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -45,7 +45,9 @@ void PrintFormatter::printKernelOutput(const std::function &print) while (currentOffset + sizeof(char *) <= printfOutputBufferSize) { char *formatString = nullptr; read(&formatString); - printString(formatString, print); + if (formatString != nullptr) { + printString(formatString, print); + } } } } diff --git a/shared/test/unit_test/program/printf_helper_tests.cpp b/shared/test/unit_test/program/printf_helper_tests.cpp index f7057d3fa5..e23417b205 100644 --- a/shared/test/unit_test/program/printf_helper_tests.cpp +++ b/shared/test/unit_test/program/printf_helper_tests.cpp @@ -957,6 +957,16 @@ TEST_F(PrintFormatterTest, GivenNoStringMapAndBufferWithFormatStringThenItIsPrin EXPECT_STREQ(formatString, output); } +TEST_F(PrintFormatterTest, GivenNoStringMapAndBufferWithEmptyFormatThenNothingIsPrinted) { + printFormatter.reset(new PrintFormatter(static_cast(data->getUnderlyingBuffer()), printfBufferSize, true)); + const char *formatString = nullptr; + storeData(formatString); + + char output[maxPrintfOutputLength]{}; + printFormatter->printKernelOutput([&output](char *str) { strncpy_s(output, maxPrintfOutputLength, str, maxPrintfOutputLength - 1); }); + EXPECT_STREQ("", output); +} + TEST_F(PrintFormatterTest, GivenNoStringMapAndBufferWithFormatStringAnd2StringsThenDataIsParsedAndPrintedProperly) { printFormatter.reset(new PrintFormatter(static_cast(data->getUnderlyingBuffer()), printfBufferSize, true)); const char *formatString = "%s %s";