From 1ded52c591efd0c8c0914ed4ae08e3913669b60b Mon Sep 17 00:00:00 2001 From: Siu Chi Chan Date: Wed, 12 May 2021 11:00:25 -0400 Subject: [PATCH] SWDEV-286082 - Fix C string processing in GPU printf This fixes an issue in hostcall when processing printf of a C string. The calculation to round-up the string size to the next data chunk didn't include the extra byte for the null terminating character. Change-Id: I4cf0c250fa4fda253b0db15be461819ffce76d32 [ROCm/clr commit: 8341fd31d186f37bb815c29c9951e19ac6d67144] --- projects/clr/rocclr/device/devhcprintf.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/projects/clr/rocclr/device/devhcprintf.cpp b/projects/clr/rocclr/device/devhcprintf.cpp index ff723ff580..ea5adcbe85 100644 --- a/projects/clr/rocclr/device/devhcprintf.cpp +++ b/projects/clr/rocclr/device/devhcprintf.cpp @@ -64,8 +64,10 @@ template static const uint64_t* consumeCstring(FILE* stream, int* outCount, const std::string& spec, const uint64_t* ptr, Args... args) { auto str = reinterpret_cast(ptr); + auto old = *outCount; checkPrintf(stream, outCount, spec.c_str(), args..., str); - return ptr + (strlen(str) + 7) / 8; + auto stringMemSize = *outCount - old + 1; + return ptr + (stringMemSize + 7) / 8; } template