[Bf-blender-cvs] [27bcbf19ed1] master: Fix possible un-initialized variable use in UI code

Julian Eisel noreply at git.blender.org
Sat Oct 3 18:56:55 CEST 2020


Commit: 27bcbf19ed1148915644139e69ebe62de7497645
Author: Julian Eisel
Date:   Sat Oct 3 18:52:14 2020 +0200
Branches: master
https://developer.blender.org/rB27bcbf19ed1148915644139e69ebe62de7497645

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.

===================================================================

M	source/blender/editors/interface/interface_layout.c

===================================================================

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 {



More information about the Bf-blender-cvs mailing list