diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-10-23 17:52:51 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-10-23 17:52:51 +0400 |
commit | e89107927bcc8297c74f9a8cb10562e6defc867c (patch) | |
tree | 7925d6bba50b803ab1ff5080e9b44b2e98a3059f /source/blender/windowmanager | |
parent | 66ef02aaa332039c2338bd4680aba34c748fb319 (diff) |
- fix for error with utf8 textinput for buttons
- ensure input is valid utf8 from ghost and NULL then complain if its not.
- added function to get utf8 size BLI_str_utf8_size()
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/WM_types.h | 4 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 12 |
2 files changed, 13 insertions, 3 deletions
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 5048166c8b7..fc96c8804b2 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -346,7 +346,9 @@ typedef struct wmEvent { short val; /* press, release, scrollvalue */ int x, y; /* mouse pointer position, screen coord */ int mval[2]; /* region mouse position, name convention pre 2.5 :) */ - char utf8_buf[6]; /* from, ghost if utf8 is enabled for the platform */ + char utf8_buf[6]; /* from, ghost if utf8 is enabled for the platform, + * BLI_str_utf8_size() must _always_ be valid, check + * when assigning s we dont need to check on every access after */ char ascii; /* from ghost, fallback if utf8 isnt set */ char pad; diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 3e9bce651a8..09ec8bf84ba 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -454,11 +454,12 @@ void WM_event_print(wmEvent *event) printf("wmEvent - type:%d/%s, val:%d/%s, " "shift:%d, ctrl:%d, alt:%d, oskey:%d, keymodifier:%d, " - "mouse:(%d,%d), ascii:'%c', utf8:'%.6s', " + "mouse:(%d,%d), ascii:'%c', utf8:'%.*s', " "keymap_idname:%s, pointer:%p\n", event->type, type_id, event->val, val_id, event->shift, event->ctrl, event->alt, event->oskey, event->keymodifier, - event->x, event->y, event->ascii, event->utf8_buf, + event->x, event->y, event->ascii, + BLI_str_utf8_size(event->utf8_buf), event->utf8_buf, event->keymap_idname, (void *)event); } else { @@ -2629,6 +2630,13 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U /* TODO. should this also zero utf8?, dont for now, campbell */ } + if (event.utf8_buf[0]) { + if (BLI_str_utf8_size(event.utf8_buf) == -1) { + printf("%s: ghost detected an invalid unicode character '%d'!\n", __func__, (int)(unsigned char)event.utf8_buf[0]); + event.utf8_buf[0]= '\0'; + } + } + /* modifiers */ /* assigning both first and second is strange - campbell */ switch(event.type) { |