Browse Source

Issue #1776 Fixed potential crash bug in ObjectCompare, because it didn't follow strict weak ordering. As counter-intuitive as it seems, a comparator must return false for equal values. The C++ standard defines and expects this behavior: true if lhs < rhs, false otherwise.

Max Vollmer 7 năm trước cách đây
mục cha
commit
990dc983ed
1 tập tin đã thay đổi với 6 bổ sung2 xóa
  1. 6 2
      code/BlenderIntermediate.h

+ 6 - 2
code/BlenderIntermediate.h

@@ -122,9 +122,11 @@ namespace Blender {
 #   pragma warning(disable:4351)
 #   pragma warning(disable:4351)
 #endif
 #endif
 
 
+    // As counter-intuitive as it may seem, a comparator must return false for equal values.
+    // The C++ standard defines and expects this behavior: true if lhs < rhs, false otherwise.
     struct ObjectCompare {
     struct ObjectCompare {
         bool operator() (const Object* left, const Object* right) const {
         bool operator() (const Object* left, const Object* right) const {
-            return ::strncmp(left->id.name, right->id.name, strlen( left->id.name ) ) == 0;
+            return ::strncmp(left->id.name, right->id.name, strlen( left->id.name ) ) < 0;
         }
         }
     };
     };
 
 
@@ -143,9 +145,11 @@ namespace Blender {
             , db(db)
             , db(db)
         {}
         {}
 
 
+        // As counter-intuitive as it may seem, a comparator must return false for equal values.
+        // The C++ standard defines and expects this behavior: true if lhs < rhs, false otherwise.
         struct ObjectCompare {
         struct ObjectCompare {
             bool operator() (const Object* left, const Object* right) const {
             bool operator() (const Object* left, const Object* right) const {
-                return ::strncmp( left->id.name, right->id.name, strlen( left->id.name ) ) == 0;
+                return ::strncmp( left->id.name, right->id.name, strlen( left->id.name ) ) < 0;
             }
             }
         };
         };