diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 9f5698e0a56e47..a4ba0a37c235b1 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -2377,7 +2377,10 @@ class ICorStaticInfo CORINFO_RESOLVED_TOKEN * pResolvedToken /* IN */) = 0; // Returns (sub)string length and content (can be null for dynamic context) - // for given metaTOK and module, length `-1` means input is incorrect + // for given metaTOK and module, length `-1` means input is incorrect. + // + // Return value: The actual length of the (sub)string. Note that this may be larger + // than bufferSize, in which case only bufferSize characters are copied to buffer. virtual int getStringLiteral ( CORINFO_MODULE_HANDLE module, /* IN */ unsigned metaTOK, /* IN */ diff --git a/src/coreclr/jit/eeinterface.cpp b/src/coreclr/jit/eeinterface.cpp index 50ca1eab333993..4b12435da5155b 100644 --- a/src/coreclr/jit/eeinterface.cpp +++ b/src/coreclr/jit/eeinterface.cpp @@ -705,7 +705,7 @@ void Compiler::eePrintObjectDescription(const char* prefix, CORINFO_OBJECT_HANDL // void Compiler::eePrintStringLiteral(CORINFO_MODULE_HANDLE module, unsigned token) { - const int MAX_LITERAL_LENGTH = 256; + const int MAX_LITERAL_LENGTH = 50; char16_t str[MAX_LITERAL_LENGTH] = {}; int length = -1; eeRunFunctorWithSPMIErrorTrap([&]() { @@ -718,9 +718,11 @@ void Compiler::eePrintStringLiteral(CORINFO_MODULE_HANDLE module, unsigned token } else { - char dst[MAX_LITERAL_LENGTH]; - convertUtf16ToUtf8ForPrinting(str, length, dst, MAX_LITERAL_LENGTH); - printf("\"%.50s%s\"", dst, length > 50 ? "..." : ""); + char dst[MAX_LITERAL_LENGTH * 3 + 1]; + // Truncate length to MAX_LITERAL_LENGTH since that's the maximum we copied into str + int truncatedLength = min(length, MAX_LITERAL_LENGTH); + convertUtf16ToUtf8ForPrinting(str, truncatedLength, dst, sizeof(dst)); + printf("\"%s%s\"", dst, length > MAX_LITERAL_LENGTH ? "..." : ""); } } #endif // DEBUG