[PATCH] wined3d: Split comments in separate line to avoid buffer overflow when traces are enabled (try 3)
Christian Costa
titan.costa at wanadoo.fr
Thu Feb 18 05:56:13 CST 2010
This time with proper memory allocation stuff + avoid printf leading // if comment string is empty
---
dlls/wined3d/shader.c | 32 +++++++++++++++++++++++++++++++-
1 files changed, 31 insertions(+), 1 deletions(-)
-------------- next part --------------
diff --git a/dlls/wined3d/shader.c b/dlls/wined3d/shader.c
index e95b4b5..cef3e74 100644
--- a/dlls/wined3d/shader.c
+++ b/dlls/wined3d/shader.c
@@ -1228,7 +1228,37 @@ static void shader_trace_init(const struct wined3d_shader_frontend *fe, void *fe
fe->shader_read_comment(&ptr, &comment);
if (comment)
{
- TRACE("//%s\n", comment);
+ if (TRACE_ON(d3d_shader))
+ {
+ int size = strlen(comment) + 1;
+ char* str = (char*)HeapAlloc(GetProcessHeap(), 0, size);
+ if (!str)
+ {
+ ERR("Cannot allocate memory for displaying comment string\n");
+ }
+ else
+ {
+ int i = 0;
+ char* line = str;
+ memcpy(str, comment, size);
+ while (i < size)
+ {
+ /* Find end of line */
+ while ((str[i] != 0) && (str[i] != 0x0a))
+ i++;
+ /* Terminate line and remove preceding 0x0d if any */
+ if (i && (str[i-1] == 0x0d))
+ str[i-1] = 0;
+ else
+ str[i] = 0;
+ /* Display line and prepare next line */
+ DPRINTF("%s%s\n", line == str ? "//" : "", debugstr_an(line, strlen(line)));
+ i++;
+ line = str + i;
+ }
+ HeapFree(GetProcessHeap(), 0, str);
+ }
+ }
continue;
}
More information about the wine-patches
mailing list