Printf handler: ensure that long format uses always 64 bit integers

Related-To: NEO-7384
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2022-10-24 14:53:33 +00:00
committed by Compute-Runtime-Automation
parent 5446b9ca0d
commit 26144d38a6
3 changed files with 107 additions and 14 deletions

View File

@@ -81,29 +81,35 @@ class PrintFormatter {
}
template <class T>
size_t typedPrintToken(char *output, size_t size, const char *formatString) {
void adjustFormatString(std::string &formatString) {}
template <class T>
size_t typedPrintToken(char *output, size_t size, const char *inputFormatString) {
T value{0};
read(&value);
constexpr auto offsetToBeDwordAligned = static_cast<uint32_t>(std::max(int64_t(sizeof(int) - sizeof(T)), int64_t(0)));
currentOffset += offsetToBeDwordAligned;
return simpleSprintf(output, size, formatString, value);
currentOffset = alignUp(currentOffset, sizeof(uint32_t));
std::string formatString(inputFormatString);
adjustFormatString<T>(formatString);
return simpleSprintf(output, size, formatString.c_str(), value);
}
template <class T>
size_t typedPrintVectorToken(char *output, size_t size, const char *formatString) {
size_t typedPrintVectorToken(char *output, size_t size, const char *inputFormatString) {
T value = {0};
int valueCount = 0;
read(&valueCount);
size_t charactersPrinted = 0;
char strippedFormat[1024];
char strippedFormat[1024]{};
stripVectorFormat(formatString, strippedFormat);
stripVectorFormat(inputFormatString, strippedFormat);
stripVectorTypeConversion(strippedFormat);
std::string formatString(strippedFormat);
adjustFormatString<T>(formatString);
for (int i = 0; i < valueCount; i++) {
read(&value);
charactersPrinted += simpleSprintf(output + charactersPrinted, size - charactersPrinted, strippedFormat, value);
charactersPrinted += simpleSprintf(output + charactersPrinted, size - charactersPrinted, formatString.c_str(), value);
if (i < valueCount - 1) {
charactersPrinted += simpleSprintf(output + charactersPrinted, size - charactersPrinted, "%c", ',');
}