From 1610549491b142207abe455578194e5cc8413e6d Mon Sep 17 00:00:00 2001 From: Ivica Ico Bukvic <ico@vt.edu> Date: Mon, 21 Jan 2013 02:51:08 -0500 Subject: [PATCH] fixed stray bug with utf8 support and symbolatom (thanks to Roman for a report). See http://sourceforge.net/tracker/?func=detail&atid=478072&aid=3160982&group_id=55736 for additional info. --- pd/src/g_text.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/pd/src/g_text.c b/pd/src/g_text.c index 204ac3e7a..557fd4692 100644 --- a/pd/src/g_text.c +++ b/pd/src/g_text.c @@ -18,6 +18,8 @@ #include "g_undo.h" #include "x_preset.h" +#include "s_utf8.h" + t_class *text_class; t_class *message_class; static t_class *gatom_class; @@ -868,8 +870,22 @@ static void gatom_key(void *z, t_floatarg f) (c >= '0' && c <= '9' || c == '.' || c == '-' || c == 'e' || c == 'E')) { - x->a_buf[len] = c; - x->a_buf[len+1] = 0; + /* the wchar could expand to up to 4 bytes, which + * which might overrun our a_buf; + * therefore we first expand into a temporary buffer, + * and only if the resulting utf8 string fits into a_buf + * we apply it + */ + char utf8[UTF8_MAXBYTES]; + int utf8len = u8_wc_toutf8(utf8, c); + if((len+utf8len) < (ATOMBUFSIZE-1)) + { + int j=0; + for(j=0; j<utf8len; j++) + x->a_buf[len+j] = utf8[j]; + + x->a_buf[len+utf8len] = 0; + } goto redraw; } } -- GitLab