diff --git a/pd/src/g_text.c b/pd/src/g_text.c index 204ac3e7ae6920027b53ae071da91b88efdb17b7..557fd469252fe22bf5f26f91c54aadd2f97f2c7b 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; } }