diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-09-02 07:27:35 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-09-02 07:57:39 +0400 |
commit | 39c7ccca1ec500b087114236c9b0dff3814dadf9 (patch) | |
tree | 8989a1f09f111bc38ae6a69bd1ffb761447937c0 /source/blender/bmesh | |
parent | 4f7caabe9dd89a527f2b153274f0d323b49cd85b (diff) |
BMesh: report errors for invalid operator use
- invalid htype's into a slot
- duplicate htype's args to BMO_op_vinitf
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operators.c | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c index 6bca5ca7a43..a4e03b1984a 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++; } |