[PATCH] wined3d: Split comments in separate line to avoid buffer overflow when traces are enabled (try 2)

Christian Costa titan.costa at wanadoo.fr
Wed Feb 17 10:54:41 CST 2010


This time use debugstr_an to handle special characters
---

 dlls/wined3d/shader.c |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)
-------------- next part --------------
diff --git a/dlls/wined3d/shader.c b/dlls/wined3d/shader.c
index e95b4b5..2ea1e9a 100644
--- a/dlls/wined3d/shader.c
+++ b/dlls/wined3d/shader.c
@@ -1228,7 +1228,30 @@ 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);
+                int i = 0;
+                char* line = str;
+                memcpy(str, comment, size);
+                DPRINTF("//");
+                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\n", debugstr_an(line, strlen(line)));
+                    i++;
+                    line = str + i;
+                }
+            }
             continue;
         }
 


More information about the wine-patches mailing list