Skip to content

Commit 571861b

Browse files
authored
JIT: Fix Compiler::printfAlloc for long strings (#116306)
1 parent ab70886 commit 571861b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/coreclr/jit/compiler.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10585,15 +10585,19 @@ const char* Compiler::devirtualizationDetailToString(CORINFO_DEVIRTUALIZATION_DE
1058510585
//
1058610586
const char* Compiler::printfAlloc(const char* format, ...)
1058710587
{
10588-
char str[512];
1058910588
va_list args;
1059010589
va_start(args, format);
10591-
int result = vsprintf_s(str, ArrLen(str), format, args);
10590+
int count = _vscprintf(format, args);
1059210591
va_end(args);
10593-
assert((result >= 0) && ((unsigned)result < ArrLen(str)));
1059410592

10595-
char* resultStr = new (this, CMK_DebugOnly) char[result + 1];
10596-
memcpy(resultStr, str, (unsigned)result + 1);
10593+
assert(count >= 0);
10594+
char* resultStr = new (this, CMK_DebugOnly) char[count + 1];
10595+
10596+
va_start(args, format);
10597+
int result = vsprintf_s(resultStr, count + 1, format, args);
10598+
va_end(args);
10599+
10600+
assert((result >= 0) && (result < (count + 1)));
1059710601
return resultStr;
1059810602
}
1059910603

0 commit comments

Comments
 (0)