vkd3d-shader: Avoid reading past the end of the buffer in vkd3d_string_buffer_trace() (Valgrind).

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2020-10-15 10:44:45 -05:00 committed by Alexandre Julliard
parent 86cf5145dc
commit dffff8bdbc

View File

@ -93,15 +93,15 @@ static int VKD3D_PRINTF_FUNC(2, 3) vkd3d_string_buffer_printf(struct vkd3d_strin
static void vkd3d_string_buffer_trace_(const struct vkd3d_string_buffer *buffer, const char *function) static void vkd3d_string_buffer_trace_(const struct vkd3d_string_buffer *buffer, const char *function)
{ {
const char *p, *q; const char *p, *q, *end = buffer->buffer + buffer->content_size;
if (!TRACE_ON()) if (!TRACE_ON())
return; return;
for (p = buffer->buffer; *p; p = q) for (p = buffer->buffer; p < end; p = q)
{ {
if (!(q = strchr(p, '\n'))) if (!(q = memchr(p, '\n', end - p)))
q = p + strlen(p); q = end;
else else
++q; ++q;
vkd3d_dbg_printf(VKD3D_DBG_LEVEL_TRACE, function, "%.*s", (int)(q - p), p); vkd3d_dbg_printf(VKD3D_DBG_LEVEL_TRACE, function, "%.*s", (int)(q - p), p);