From 0c6cd3ba21ccdbb934dae16713b4fb2c6988ff0f Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Sat, 3 Oct 2020 16:25:11 -0500 Subject: [PATCH] vkd3d-common: Correctly escape whitespace characters in debugstr_*(). Signed-off-by: Zebediah Figura Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- libs/vkd3d-common/debug.c | 66 +++++++++++++-------------------------- 1 file changed, 21 insertions(+), 45 deletions(-) diff --git a/libs/vkd3d-common/debug.c b/libs/vkd3d-common/debug.c index 33deed65..5e49cf10 100644 --- a/libs/vkd3d-common/debug.c +++ b/libs/vkd3d-common/debug.c @@ -114,6 +114,24 @@ const char *vkd3d_dbg_sprintf(const char *fmt, ...) return buffer; } +static int get_escape_char(int c) +{ + switch (c) + { + case '"': + case '\\': + return c; + case '\t': + return 't'; + case '\n': + return 'n'; + case '\r': + return 'r'; + default: + return 0; + } +} + const char *debugstr_a(const char *str) { char *buffer, *ptr; @@ -127,21 +145,7 @@ const char *debugstr_a(const char *str) *ptr++ = '"'; while ((c = *str++) && ptr <= buffer + VKD3D_DEBUG_BUFFER_SIZE - 8) { - int escape_char; - - switch (c) - { - case '"': - case '\\': - case '\n': - case '\r': - case '\t': - escape_char = c; - break; - default: - escape_char = 0; - break; - } + int escape_char = get_escape_char(c); if (escape_char) { @@ -187,21 +191,7 @@ static const char *debugstr_w16(const uint16_t *wstr) *ptr++ = '"'; while ((c = *wstr++) && ptr <= buffer + VKD3D_DEBUG_BUFFER_SIZE - 10) { - int escape_char; - - switch (c) - { - case '"': - case '\\': - case '\n': - case '\r': - case '\t': - escape_char = c; - break; - default: - escape_char = 0; - break; - } + int escape_char = get_escape_char(c); if (escape_char) { @@ -247,21 +237,7 @@ static const char *debugstr_w32(const uint32_t *wstr) *ptr++ = '"'; while ((c = *wstr++) && ptr <= buffer + VKD3D_DEBUG_BUFFER_SIZE - 10) { - int escape_char; - - switch (c) - { - case '"': - case '\\': - case '\n': - case '\r': - case '\t': - escape_char = c; - break; - default: - escape_char = 0; - break; - } + int escape_char = get_escape_char(c); if (escape_char) {