aboutsummaryrefslogtreecommitdiff
path: root/packages/patches/fix_gui_%_crash-0.42-4.patch
blob: 02c393131bcc81edce8e0e4cdd9f9e3f6c4eb687 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Index: x_gui.c
===================================================================
--- x_gui.c	(revision 11016)
+++ x_gui.c	(working copy)
@@ -49,6 +49,9 @@
 {
     char buf[4*MAXPDSTRING];
     char namebuf[80];
+    char sprintfbuf[MAXPDSTRING];
+    char *afterpercent;
+    t_int afterpercentlen;
     t_gfxstub *x;
     t_symbol *s;
         /* if any exists with matching key, burn it. */
@@ -71,7 +74,13 @@
     x->x_key = key;
     x->x_next = gfxstub_list;
     gfxstub_list = x;
-    sprintf(buf, cmd, s->s_name);
+    /* only replace first %s so sprintf() doesn't crash */
+    afterpercent = strchr(cmd, '%') + 2;
+    afterpercentlen = afterpercent - cmd;
+    strncpy(sprintfbuf, cmd, afterpercentlen);
+    sprintfbuf[afterpercentlen] = '\0';
+    sprintf(buf, sprintfbuf, s->s_name);
+    strncat(buf, afterpercent, (4*MAXPDSTRING) - afterpercentlen);
     sys_gui(buf);
 }