From 993ae7195957052eb3cef8737ea5564ae2913322 Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Fri, 12 Feb 2016 16:32:33 -0500
Subject: [PATCH] fix braindead implementation of escaping double quotes in
 strings (I forgot to actually test the branch that handles strings with
 quotes in them)

---
 pd/src/s_inter.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/pd/src/s_inter.c b/pd/src/s_inter.c
index d805ef898..e1e54c1ef 100644
--- a/pd/src/s_inter.c
+++ b/pd/src/s_inter.c
@@ -775,17 +775,22 @@ static void escape_double_quotes(const char *src) {
         sys_vgui("\"%s\"", src);
     else
     {
-        char *dest = (char *)t_getbytes((len+1)*sizeof(*dest));
+        char *dest = (char *)t_getbytes((len+dq+1)*sizeof(*dest));
+        char *tmp = dest;
         s = src;
         while(*s++)
         {
             if (*s == '\"')
-                *dest++ = '\\', *dest++ = '\"';
+            {
+                *tmp++ = '\\';
+                *tmp++ = '\"';
+            }
             else
-                *dest++ = *s;
+                *tmp++ = *s;
         }
+        *tmp = '\0'; /* null terminate */
         sys_vgui("\"%s\"", dest);
-        t_freebytes(dest, (len+1)*sizeof(*dest));
+        t_freebytes(dest, (len+dq+1)*sizeof(*dest));
     }
 }
 
-- 
GitLab