diff options
author | Julian Eisel <julian@blender.org> | 2020-10-03 19:52:14 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2020-10-03 19:56:19 +0300 |
commit | 27bcbf19ed1148915644139e69ebe62de7497645 (patch) | |
tree | 5a5c8051295dd2c3110581de1e9e44783a8a1a89 /source/blender/editors/interface/interface_layout.c | |
parent | 3a1cf838ca09bdc58eeab67ced640314faf49eae (diff) |
Fix possible un-initialized variable use in UI code
Uncovered by a4aa94c41cb7. Before that, it would actually be a possible `NULL`
pointer dereference.
It would happen if a `UILayout.prop()` was placed with the `full_event` option
set to `True` (or the C equivalent) for a non keymap-item property.
Now this the `full_event` option is ignored then with a warning print.
Diffstat (limited to 'source/blender/editors/interface/interface_layout.c')
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 8b59e85ec56..605930c6111 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -938,6 +938,12 @@ static uiBut *ui_item_with_label(uiLayout *layout, (layout->item.flag & UI_ITEM_PROP_DECORATE_NO_PAD) == 0; #endif + const bool is_keymapitem_ptr = RNA_struct_is_a(ptr->type, &RNA_KeyMapItem); + if ((flag & flag & UI_ITEM_R_FULL_EVENT) && is_keymapitem_ptr) { + RNA_warning("Data is not a keymap item struct: %s. Ignoring 'full_event' option.", + RNA_struct_identifier(ptr->type)); + } + UI_block_layout_set_current(block, layout); /* Only add new row if more than 1 item will be added. */ @@ -1010,32 +1016,30 @@ static uiBut *ui_item_with_label(uiLayout *layout, -1, NULL); } - else if (flag & UI_ITEM_R_FULL_EVENT) { - if (RNA_struct_is_a(ptr->type, &RNA_KeyMapItem)) { - char buf[128]; - - WM_keymap_item_to_string(ptr->data, false, buf, sizeof(buf)); - - but = uiDefButR_prop(block, - UI_BTYPE_HOTKEY_EVENT, - 0, - buf, - x, - y, - prop_but_width, - h, - ptr, - prop, - 0, - 0, - 0, - -1, - -1, - NULL); - UI_but_func_set(but, ui_keymap_but_cb, but, NULL); - if (flag & UI_ITEM_R_IMMEDIATE) { - UI_but_flag_enable(but, UI_BUT_IMMEDIATE); - } + else if ((flag & UI_ITEM_R_FULL_EVENT) && is_keymapitem_ptr) { + char buf[128]; + + WM_keymap_item_to_string(ptr->data, false, buf, sizeof(buf)); + + but = uiDefButR_prop(block, + UI_BTYPE_HOTKEY_EVENT, + 0, + buf, + x, + y, + prop_but_width, + h, + ptr, + prop, + 0, + 0, + 0, + -1, + -1, + NULL); + UI_but_func_set(but, ui_keymap_but_cb, but, NULL); + if (flag & UI_ITEM_R_IMMEDIATE) { + UI_but_flag_enable(but, UI_BUT_IMMEDIATE); } } else { |