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:
2012-11-26 03:47:20 +00:00
parent 3d64381e4d
commit e77e1f183a
5 changed files with 22 additions and 14 deletions

View File

@@ -185,7 +185,7 @@ BLI_INLINE int BMO_slot_map_bool_get(BMOpSlot *slot, const void *element)
return 0; 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); void **val = (void **) BMO_slot_map_data_get(slot, element);
BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL); BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL);

View File

@@ -860,16 +860,21 @@ static int ed_marker_move_modal(bContext *C, wmOperator *op, wmEvent *evt)
} }
if (evt->val == KM_PRESS) { if (evt->val == KM_PRESS) {
float vec;
char str_tx[NUM_STR_REP_LEN];
if (handleNumInput(&mm->num, evt)) { if (handleNumInput(&mm->num, evt)) {
applyNumInput(&mm->num, &vec); char str_tx[NUM_STR_REP_LEN];
outputNumInput(&mm->num, str_tx); float value = RNA_int_get(op->ptr, "frames");
applyNumInput(&mm->num, &value);
RNA_int_set(op->ptr, "frames", vec);
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_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); // strcat(str, str_tx);
BLI_snprintf(str, sizeof(str), "Marker offset %s", str_tx); BLI_snprintf(str, sizeof(str), "Marker offset %s", str_tx);
ED_area_headerprint(CTX_wm_area(C), str); ED_area_headerprint(CTX_wm_area(C), str);

View File

@@ -552,9 +552,9 @@ static int loopcut_modal(bContext *C, wmOperator *op, wmEvent *event)
/* using the keyboard to input the number of cuts */ /* using the keyboard to input the number of cuts */
if (event->val == KM_PRESS) { if (event->val == KM_PRESS) {
/* init as zero so backspace clears */ /* init as zero so backspace clears */
float value = 0.0f;
if (handleNumInput(&lcd->num, event)) { if (handleNumInput(&lcd->num, event)) {
float value = RNA_int_get(op->ptr, "number_cuts");
applyNumInput(&lcd->num, &value); applyNumInput(&lcd->num, &value);
/* allow zero so you can backspace and type in a value /* allow zero so you can backspace and type in a value

View File

@@ -4973,9 +4973,9 @@ static int edbm_bevel_modal(bContext *C, wmOperator *op, wmEvent *event)
if (event->val == KM_PRESS) { if (event->val == KM_PRESS) {
/* Try to handle numeric inputs... */ /* Try to handle numeric inputs... */
#ifdef NEW_BEVEL #ifdef NEW_BEVEL
float value;
if (handleNumInput(&opdata->num_input, event)) { if (handleNumInput(&opdata->num_input, event)) {
float value = RNA_float_get(op->ptr, "offset");
applyNumInput(&opdata->num_input, &value); applyNumInput(&opdata->num_input, &value);
RNA_float_set(op->ptr, "offset", value); RNA_float_set(op->ptr, "offset", value);
edbm_bevel_calc(C, op); edbm_bevel_calc(C, op);
@@ -4983,9 +4983,8 @@ static int edbm_bevel_modal(bContext *C, wmOperator *op, wmEvent *event)
return OPERATOR_RUNNING_MODAL; return OPERATOR_RUNNING_MODAL;
} }
#else #else
float factor;
if (handleNumInput(&opdata->num_input, event)) { if (handleNumInput(&opdata->num_input, event)) {
float factor = RNA_float_get(op->ptr, "percent");
applyNumInput(&opdata->num_input, &factor); applyNumInput(&opdata->num_input, &factor);
CLAMP(factor, 0.0f, 1.0f); CLAMP(factor, 0.0f, 1.0f);
RNA_float_set(op->ptr, "percent", factor); 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) { if (event->val == KM_PRESS) {
/* Try to handle numeric inputs... */ /* Try to handle numeric inputs... */
float amounts[2];
if (handleNumInput(&opdata->num_input, event)) { 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); applyNumInput(&opdata->num_input, amounts);
amounts[0] = max_ff(amounts[0], 0.0f); amounts[0] = max_ff(amounts[0], 0.0f);
RNA_float_set(op->ptr, "thickness", amounts[0]); RNA_float_set(op->ptr, "thickness", amounts[0]);

View File

@@ -130,6 +130,9 @@ short hasNumInput(NumInput *n)
return 0; return 0;
} }
/**
* \warning \a vec must be set beforehand otherwise we risk uninitialized vars.
*/
void applyNumInput(NumInput *n, float *vec) void applyNumInput(NumInput *n, float *vec)
{ {
short i, j; short i, j;