[Bf-blender-cvs] [0438944b343] blender-v2.83-release: Refactor/strengthen a bit invalid operands checks when applying an override operation.

Bastien Montagne noreply at git.blender.org
Thu Apr 16 16:21:17 CEST 2020


Commit: 0438944b343ed11abad47964f4dccb4e171da179
Author: Bastien Montagne
Date:   Wed Apr 15 17:26:34 2020 +0200
Branches: blender-v2.83-release
https://developer.blender.org/rB0438944b343ed11abad47964f4dccb4e171da179

Refactor/strengthen a bit invalid operands checks when applying an override operation.

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

M	source/blender/blenkernel/BKE_lib_override.h
M	source/blender/blenkernel/intern/lib_override.c
M	source/blender/makesrna/intern/rna_access_compare_override.c

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

diff --git a/source/blender/blenkernel/BKE_lib_override.h b/source/blender/blenkernel/BKE_lib_override.h
index 6f2882f3565..699d1ee23e9 100644
--- a/source/blender/blenkernel/BKE_lib_override.h
+++ b/source/blender/blenkernel/BKE_lib_override.h
@@ -48,6 +48,8 @@ struct IDOverrideLibrary;
 struct IDOverrideLibraryProperty;
 struct IDOverrideLibraryPropertyOperation;
 struct Main;
+struct PointerRNA;
+struct PropertyRNA;
 
 void BKE_lib_override_library_enable(const bool do_enable);
 bool BKE_lib_override_library_is_enabled(void);
@@ -92,6 +94,15 @@ void BKE_lib_override_library_property_operation_delete(
     struct IDOverrideLibraryProperty *override_property,
     struct IDOverrideLibraryPropertyOperation *override_property_operation);
 
+bool BKE_lib_override_library_property_operation_operands_validate(
+    struct IDOverrideLibraryPropertyOperation *override_property_operation,
+    struct PointerRNA *ptr_dst,
+    struct PointerRNA *ptr_src,
+    struct PointerRNA *ptr_storage,
+    struct PropertyRNA *prop_dst,
+    struct PropertyRNA *prop_src,
+    struct PropertyRNA *prop_storage);
+
 bool BKE_lib_override_library_status_check_local(struct Main *bmain, struct ID *local);
 bool BKE_lib_override_library_status_check_reference(struct Main *bmain, struct ID *local);
 
diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c
index 5b75b8ac181..6a206fc46d9 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.c
@@ -558,6 +558,46 @@ void BKE_lib_override_library_property_operation_delete(
   BLI_freelinkN(&override_property->operations, override_property_operation);
 }
 
+/**
+ * Validate that required data for a given operation are available.
+ */
+bool BKE_lib_override_library_property_operation_operands_validate(
+    struct IDOverrideLibraryPropertyOperation *override_property_operation,
+    struct PointerRNA *ptr_dst,
+    struct PointerRNA *ptr_src,
+    struct PointerRNA *ptr_storage,
+    struct PropertyRNA *prop_dst,
+    struct PropertyRNA *prop_src,
+    struct PropertyRNA *prop_storage)
+{
+  switch (override_property_operation->operation) {
+    case IDOVERRIDE_LIBRARY_OP_NOOP:
+      return true;
+    case IDOVERRIDE_LIBRARY_OP_ADD:
+      ATTR_FALLTHROUGH;
+    case IDOVERRIDE_LIBRARY_OP_SUBTRACT:
+      ATTR_FALLTHROUGH;
+    case IDOVERRIDE_LIBRARY_OP_MULTIPLY:
+      if (ptr_storage == NULL || ptr_storage->data == NULL || prop_storage == NULL) {
+        BLI_assert(!"Missing data to apply differential override operation.");
+        return false;
+      }
+      ATTR_FALLTHROUGH;
+    case IDOVERRIDE_LIBRARY_OP_INSERT_AFTER:
+      ATTR_FALLTHROUGH;
+    case IDOVERRIDE_LIBRARY_OP_INSERT_BEFORE:
+      ATTR_FALLTHROUGH;
+    case IDOVERRIDE_LIBRARY_OP_REPLACE:
+      if ((ptr_dst == NULL || ptr_dst->data == NULL || prop_dst == NULL) ||
+          (ptr_src == NULL || ptr_src->data == NULL || prop_src == NULL)) {
+        BLI_assert(!"Missing data to apply override operation.");
+        return false;
+      }
+  }
+
+  return true;
+}
+
 /**
  * Check that status of local data-block is still valid against current reference one.
  *
diff --git a/source/blender/makesrna/intern/rna_access_compare_override.c b/source/blender/makesrna/intern/rna_access_compare_override.c
index 199d22ee3dc..32b375fda97 100644
--- a/source/blender/makesrna/intern/rna_access_compare_override.c
+++ b/source/blender/makesrna/intern/rna_access_compare_override.c
@@ -481,28 +481,13 @@ static bool rna_property_override_operation_apply(Main *bmain,
 
   const short override_op = opop->operation;
 
-  if (override_op == IDOVERRIDE_LIBRARY_OP_NOOP) {
-    return true;
-  }
-
-  if (ELEM(override_op,
-           IDOVERRIDE_LIBRARY_OP_ADD,
-           IDOVERRIDE_LIBRARY_OP_SUBTRACT,
-           IDOVERRIDE_LIBRARY_OP_MULTIPLY) &&
-      !ptr_storage) {
-    /* We cannot apply 'diff' override operations without some reference storage.
-     * This should typically only happen at read time of .blend file... */
+  if (!BKE_lib_override_library_property_operation_operands_validate(
+          opop, ptr_dst, ptr_src, ptr_storage, prop_dst, prop_src, prop_storage)) {
     return false;
   }
 
-  if (ELEM(override_op,
-           IDOVERRIDE_LIBRARY_OP_ADD,
-           IDOVERRIDE_LIBRARY_OP_SUBTRACT,
-           IDOVERRIDE_LIBRARY_OP_MULTIPLY) &&
-      !prop_storage) {
-    /* We cannot apply 'diff' override operations without some reference storage.
-     * This should typically only happen at read time of .blend file... */
-    return false;
+  if (override_op == IDOVERRIDE_LIBRARY_OP_NOOP) {
+    return true;
   }
 
   RNAPropOverrideApply override_apply = NULL;



More information about the Bf-blender-cvs mailing list