fix: handle empty print format in case without string map

https://github.com/intel/compute-runtime/issues/635
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2023-04-21 07:54:32 +02:00
committed by Compute-Runtime-Automation
parent c93b084a4b
commit 1a1bd04d4a
2 changed files with 14 additions and 2 deletions

View File

@@ -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<void(char *)> &print)
while (currentOffset + sizeof(char *) <= printfOutputBufferSize) {
char *formatString = nullptr;
read(&formatString);
printString(formatString, print);
if (formatString != nullptr) {
printString(formatString, print);
}
}
}
}

View File

@@ -957,6 +957,16 @@ TEST_F(PrintFormatterTest, GivenNoStringMapAndBufferWithFormatStringThenItIsPrin
EXPECT_STREQ(formatString, output);
}
TEST_F(PrintFormatterTest, GivenNoStringMapAndBufferWithEmptyFormatThenNothingIsPrinted) {
printFormatter.reset(new PrintFormatter(static_cast<uint8_t *>(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<uint8_t *>(data->getUnderlyingBuffer()), printfBufferSize, true));
const char *formatString = "%s %s";