mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-14 00:39:55 +02:00
Fixed text functions fast-path for handling "%s" and "%.*s" to handle null pointers gracefully. (#7016, #3466, #6846)
This commit is contained in:
@ -1944,6 +1944,8 @@ void ImFormatStringToTempBufferV(const char** out_buf, const char** out_buf_end,
|
||||
if (fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 0)
|
||||
{
|
||||
const char* buf = va_arg(args, const char*); // Skip formatting when using "%s"
|
||||
if (buf == NULL)
|
||||
buf = "(null)";
|
||||
*out_buf = buf;
|
||||
if (out_buf_end) { *out_buf_end = buf + strlen(buf); }
|
||||
}
|
||||
@ -1951,6 +1953,11 @@ void ImFormatStringToTempBufferV(const char** out_buf, const char** out_buf_end,
|
||||
{
|
||||
int buf_len = va_arg(args, int); // Skip formatting when using "%.*s"
|
||||
const char* buf = va_arg(args, const char*);
|
||||
if (buf == NULL)
|
||||
{
|
||||
buf = "(null)";
|
||||
buf_len = ImMin(buf_len, 6);
|
||||
}
|
||||
*out_buf = buf;
|
||||
*out_buf_end = buf + buf_len; // Disallow not passing 'out_buf_end' here. User is expected to use it.
|
||||
}
|
||||
|
Reference in New Issue
Block a user