[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41238] trunk/blender/source/blender/ editors/interface/interface_handlers.c: fix for crash when entering in non unicode ascii chars.
Campbell Barton
ideasman42 at gmail.com
Mon Oct 24 08:57:55 CEST 2011
Revision: 41238
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41238
Author: campbellbarton
Date: 2011-10-24 06:57:53 +0000 (Mon, 24 Oct 2011)
Log Message:
-----------
fix for crash when entering in non unicode ascii chars.
now allow these but only for filepaths.
Modified Paths:
--------------
trunk/blender/source/blender/editors/interface/interface_handlers.c
Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c 2011-10-24 06:19:17 UTC (rev 41237)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c 2011-10-24 06:57:53 UTC (rev 41238)
@@ -1437,8 +1437,11 @@
ui_check_but(but);
}
-/* note: utf8 & ascii funcs should be merged */
-static int ui_textedit_type_utf8(uiBut *but, uiHandleButtonData *data, const char utf8_buf[6])
+/* this is used for both utf8 and ascii, its meant to be used for single keys,
+ * notie the buffer is either copied or not, so its not suitable for pasting in
+ * - campbell */
+static int ui_textedit_type_buf(uiBut *but, uiHandleButtonData *data,
+ const char *utf8_buf, int utf8_buf_len)
{
char *str;
int len, changed= 0;
@@ -1447,7 +1450,7 @@
len= strlen(str);
if(len-(but->selend - but->selsta)+1 <= data->maxlen) {
- int step= BLI_str_utf8_size(utf8_buf);
+ int step= utf8_buf_len;
/* type over the current selection */
if ((but->selend - but->selsta) > 0) {
@@ -1468,8 +1471,17 @@
static int ui_textedit_type_ascii(uiBut *but, uiHandleButtonData *data, char ascii)
{
- char utf8_buf[6]= {ascii, '\0'};
- return ui_textedit_type_utf8(but, data, utf8_buf);
+ char buf[2]= {ascii, '\0'};
+
+ if (ui_is_but_utf8(but) && (BLI_str_utf8_size(buf) == -1)) {
+ printf("%s: entering invalid ascii char into an ascii key (%d)\n",
+ __func__, (int)(unsigned char)ascii);
+
+ return 0;
+ }
+
+ /* in some cases we want to allow invalid utf8 chars */
+ return ui_textedit_type_buf(but, data, buf, 1);
}
static void ui_textedit_move(uiBut *but, uiHandleButtonData *data, int direction, int select, uiButtonJumpType jump)
@@ -1943,7 +1955,7 @@
/* keep this printf until utf8 is well tested */
printf("%s: utf8 char '%s'\n", __func__, event->utf8_buf);
// strcpy(event->utf8_buf, "12345");
- changed= ui_textedit_type_utf8(but, data, event->utf8_buf);
+ changed= ui_textedit_type_buf(but, data, event->utf8_buf, BLI_str_utf8_size(event->utf8_buf));
}
else {
changed= ui_textedit_type_ascii(but, data, ascii);
More information about the Bf-blender-cvs
mailing list