Commit: 39c7ccca1ec500b087114236c9b0dff3814dadf9
Author: Campbell Barton
Date:   Tue Sep 2 13:27:35 2014 +1000
Branches: master
https://developer.blender.org/rB39c7ccca1ec500b087114236c9b0dff3814dadf9

BMesh: report errors for invalid operator use

- invalid htype's into a slot
- duplicate htype's args to BMO_op_vinitf

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

M       source/blender/bmesh/intern/bmesh_operators.c

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

diff --git a/source/blender/bmesh/intern/bmesh_operators.c 
b/source/blender/bmesh/intern/bmesh_operators.c
index 6bca5ca..a4e03b1 100644
--- a/source/blender/bmesh/intern/bmesh_operators.c
+++ b/source/blender/bmesh/intern/bmesh_operators.c
@@ -765,6 +765,9 @@ void BMO_slot_buffer_from_all(BMesh *bm, BMOperator *op, 
BMOpSlot slot_args[BMO_
        BMOpSlot *output = BMO_slot_get(slot_args, slot_name);
        int totelement = 0, i = 0;
        
+       BLI_assert(output->slot_type == BMO_OP_SLOT_ELEMENT_BUF);
+       BLI_assert(((output->slot_subtype.elem & BM_ALL_NOLOOP) & htype) == 
htype);
+
        if (htype & BM_VERT) totelement += bm->totvert;
        if (htype & BM_EDGE) totelement += bm->totedge;
        if (htype & BM_FACE) totelement += bm->totface;
@@ -812,7 +815,11 @@ static void bmo_slot_buffer_from_hflag(BMesh *bm, 
BMOperator *op, BMOpSlot slot_
 {
        BMOpSlot *output = BMO_slot_get(slot_args, slot_name);
        int totelement = 0, i = 0;
-       const int respecthide = (op->flag & BMO_FLAG_RESPECT_HIDE) != 0;
+       const bool respecthide = (op->flag & BMO_FLAG_RESPECT_HIDE) != 0;
+
+       BLI_assert(output->slot_type == BMO_OP_SLOT_ELEMENT_BUF);
+       BLI_assert(((output->slot_subtype.elem & BM_ALL_NOLOOP) & htype) == 
htype);
+       BLI_assert((output->slot_subtype.elem & 
BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) == 0);
 
        if (test_for_enabled)
                totelement = BM_mesh_elem_hflag_count_enabled(bm, htype, hflag, 
respecthide);
@@ -952,14 +959,15 @@ static void bmo_slot_buffer_from_flag(BMesh *bm, 
BMOperator *op,
 
        BLI_assert(op->slots_in == slot_args || op->slots_out == slot_args);
 
+       BLI_assert(slot->slot_type == BMO_OP_SLOT_ELEMENT_BUF);
+       BLI_assert(((slot->slot_subtype.elem & BM_ALL_NOLOOP) & htype) == 
htype);
+       BLI_assert((slot->slot_subtype.elem & 
BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) == 0);
+
        if (test_for_enabled)
                totelement = BMO_mesh_enabled_flag_count(bm, htype, oflag);
        else
                totelement = BMO_mesh_disabled_flag_count(bm, htype, oflag);
 
-       BLI_assert(slot->slot_type == BMO_OP_SLOT_ELEMENT_BUF);
-       BLI_assert(((slot->slot_subtype.elem & BM_ALL_NOLOOP) & htype) == 
htype);
-
        if (totelement) {
                BMIter iter;
                BMHeader *ele;
@@ -1035,6 +1043,7 @@ void BMO_slot_buffer_hflag_enable(BMesh *bm,
 
        BLI_assert(slot->slot_type == BMO_OP_SLOT_ELEMENT_BUF);
        BLI_assert(((slot->slot_subtype.elem & BM_ALL_NOLOOP) & htype) == 
htype);
+       BLI_assert((slot->slot_subtype.elem & 
BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) == 0);
 
        for (i = 0; i < slot->len; i++, data++) {
                if (!(htype & (*data)->head.htype))
@@ -1655,7 +1664,6 @@ bool BMO_op_vinitf(BMesh *bm, BMOperator *op, const int 
flag, const char *_fmt,
        char slot_name[64] = {0};
        int i, type;
        bool noslot, state;
-       char htype;
 
 
        /* basic useful info to help find where bmop formatting strings fail */
@@ -1730,9 +1738,8 @@ bool BMO_op_vinitf(BMesh *bm, BMOperator *op, const int 
flag, const char *_fmt,
                                        break;
                                case 'm':
                                {
-                                       int size, c;
-
-                                       c = NEXT_CHAR(fmt);
+                                       int size;
+                                       const char c = NEXT_CHAR(fmt);
                                        fmt++;
 
                                        if      (c == '3') size = 3;
@@ -1801,22 +1808,23 @@ bool BMO_op_vinitf(BMesh *bm, BMOperator *op, const int 
flag, const char *_fmt,
                                                
BMO_slot_float_set(op->slots_in, slot_name, va_arg(vlist, double));
                                        }
                                        else {
-                                               bool stop = false;
+                                               char htype = 0;
 
-                                               htype = 0;
                                                while (1) {
-                                                       switch (NEXT_CHAR(fmt)) 
{
-                                                               case 'f': htype 
|= BM_FACE; break;
-                                                               case 'e': htype 
|= BM_EDGE; break;
-                                                               case 'v': htype 
|= BM_VERT; break;
-                                                               default:
-                                                                       stop = 
true;
-                                                                       break;
-                                                       }
-                                                       if (stop) {
+                                                       char htype_set;
+                                                       const char c = 
NEXT_CHAR(fmt);
+                                                       if      (c == 'f') 
htype_set = BM_FACE;
+                                                       else if (c == 'e') 
htype_set = BM_EDGE;
+                                                       else if (c == 'v') 
htype_set = BM_VERT;
+                                                       else {
                                                                break;
                                                        }
 
+                                                       if (UNLIKELY(htype & 
htype_set)) {
+                                                               
GOTO_ERROR("htype duplicated");
+                                                       }
+
+                                                       htype |= htype_set;
                                                        fmt++;
                                                }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to