fix for uninitialized memory use with numeric input:
bevel/inset/marker-move would use uninitialized memory when used as modal operators and pressing backspace after entering values.
This commit is contained in:
@@ -185,7 +185,7 @@ BLI_INLINE int BMO_slot_map_bool_get(BMOpSlot *slot, const void *element)
|
||||
return 0;
|
||||
}
|
||||
|
||||
BLI_INLINE void *BMO_slot_map_ptr_get_(BMOpSlot *slot, const void *element)
|
||||
BLI_INLINE void *BMO_slot_map_ptr_get(BMOpSlot *slot, const void *element)
|
||||
{
|
||||
void **val = (void **) BMO_slot_map_data_get(slot, element);
|
||||
BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL);
|
||||
|
||||
@@ -860,16 +860,21 @@ static int ed_marker_move_modal(bContext *C, wmOperator *op, wmEvent *evt)
|
||||
}
|
||||
|
||||
if (evt->val == KM_PRESS) {
|
||||
float vec;
|
||||
char str_tx[NUM_STR_REP_LEN];
|
||||
|
||||
if (handleNumInput(&mm->num, evt)) {
|
||||
applyNumInput(&mm->num, &vec);
|
||||
outputNumInput(&mm->num, str_tx);
|
||||
|
||||
RNA_int_set(op->ptr, "frames", vec);
|
||||
char str_tx[NUM_STR_REP_LEN];
|
||||
float value = RNA_int_get(op->ptr, "frames");
|
||||
applyNumInput(&mm->num, &value);
|
||||
|
||||
if (hasNumInput(&mm->num)) {
|
||||
outputNumInput(&mm->num, str_tx);
|
||||
}
|
||||
else {
|
||||
BLI_snprintf(str_tx, sizeof(str_tx), "%d", (int)value);
|
||||
}
|
||||
|
||||
RNA_int_set(op->ptr, "frames", value);
|
||||
ed_marker_move_apply(C, op);
|
||||
// ed_marker_header_update(C, op, str, (int)vec[0]);
|
||||
// ed_marker_header_update(C, op, str, (int)value);
|
||||
// strcat(str, str_tx);
|
||||
BLI_snprintf(str, sizeof(str), "Marker offset %s", str_tx);
|
||||
ED_area_headerprint(CTX_wm_area(C), str);
|
||||
|
||||
@@ -552,9 +552,9 @@ static int loopcut_modal(bContext *C, wmOperator *op, wmEvent *event)
|
||||
/* using the keyboard to input the number of cuts */
|
||||
if (event->val == KM_PRESS) {
|
||||
/* init as zero so backspace clears */
|
||||
float value = 0.0f;
|
||||
|
||||
if (handleNumInput(&lcd->num, event)) {
|
||||
float value = RNA_int_get(op->ptr, "number_cuts");
|
||||
applyNumInput(&lcd->num, &value);
|
||||
|
||||
/* allow zero so you can backspace and type in a value
|
||||
|
||||
@@ -4973,9 +4973,9 @@ static int edbm_bevel_modal(bContext *C, wmOperator *op, wmEvent *event)
|
||||
if (event->val == KM_PRESS) {
|
||||
/* Try to handle numeric inputs... */
|
||||
#ifdef NEW_BEVEL
|
||||
float value;
|
||||
|
||||
if (handleNumInput(&opdata->num_input, event)) {
|
||||
float value = RNA_float_get(op->ptr, "offset");
|
||||
applyNumInput(&opdata->num_input, &value);
|
||||
RNA_float_set(op->ptr, "offset", value);
|
||||
edbm_bevel_calc(C, op);
|
||||
@@ -4983,9 +4983,8 @@ static int edbm_bevel_modal(bContext *C, wmOperator *op, wmEvent *event)
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
}
|
||||
#else
|
||||
float factor;
|
||||
|
||||
if (handleNumInput(&opdata->num_input, event)) {
|
||||
float factor = RNA_float_get(op->ptr, "percent");
|
||||
applyNumInput(&opdata->num_input, &factor);
|
||||
CLAMP(factor, 0.0f, 1.0f);
|
||||
RNA_float_set(op->ptr, "percent", factor);
|
||||
@@ -5365,9 +5364,10 @@ static int edbm_inset_modal(bContext *C, wmOperator *op, wmEvent *event)
|
||||
|
||||
if (event->val == KM_PRESS) {
|
||||
/* Try to handle numeric inputs... */
|
||||
float amounts[2];
|
||||
|
||||
if (handleNumInput(&opdata->num_input, event)) {
|
||||
float amounts[2] = {RNA_float_get(op->ptr, "thickness"),
|
||||
RNA_float_get(op->ptr, "depth")};
|
||||
applyNumInput(&opdata->num_input, amounts);
|
||||
amounts[0] = max_ff(amounts[0], 0.0f);
|
||||
RNA_float_set(op->ptr, "thickness", amounts[0]);
|
||||
|
||||
@@ -130,6 +130,9 @@ short hasNumInput(NumInput *n)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \warning \a vec must be set beforehand otherwise we risk uninitialized vars.
|
||||
*/
|
||||
void applyNumInput(NumInput *n, float *vec)
|
||||
{
|
||||
short i, j;
|
||||
|
||||
Reference in New Issue
Block a user