Add some security checks against future bad float UIprecision values.

This commit and previous one should be backported to 2.79a should we
release it.
This commit is contained in:
Bastien Montagne 2017-09-18 19:50:40 +02:00
parent 785e96a11d
commit bb4a12914f
Notes: blender-bot 2023-02-14 06:34:43 +01:00
Referenced by issue #53683, 2.79a release
Referenced by issue #52845, JPEG 2000 Images rendering pink on macOS - Cycles
Referenced by issue #52823, New Depsgraph - Shrinkwrap crashes blender
Referenced by issue #52761, BMesh Boolean - Freaks out sometimes
3 changed files with 10 additions and 20 deletions

View File

@ -996,7 +996,7 @@ void uiItemsFullEnumO(
struct IDProperty *properties, int context, int flag);
void uiItemsFullEnumO_items(
uiLayout *layout, struct wmOperatorType *ot, PointerRNA ptr, PropertyRNA *prop,
IDProperty *properties, int context, int flag,
struct IDProperty *properties, int context, int flag,
const EnumPropertyItem *item_array, int totitem);
void uiItemL(uiLayout *layout, const char *name, int icon); /* label */

View File

@ -488,6 +488,9 @@ static int ui_but_calc_float_precision(uiBut *but, double value)
else if (prec == -1) {
prec = (but->hardmax < 10.001f) ? 3 : 2;
}
else {
CLAMP(prec, 0, UI_PRECISION_FLOAT_MAX);
}
return UI_calc_float_precision(prec, value);
}

View File

@ -44,6 +44,8 @@
#include "BLT_translation.h"
#include "UI_interface.h" /* For things like UI_PRECISION_FLOAT_MAX... */
#include "RNA_define.h"
#include "rna_internal.h"
@ -1405,13 +1407,13 @@ void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, bool consecutive)
* For ints, whole values are used.
*
* \param precision The number of zeros to show
* (as a whole number - common range is 1 - 6), see PRECISION_FLOAT_MAX
* (as a whole number - common range is 1 - 6), see UI_PRECISION_FLOAT_MAX
*/
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
{
StructRNA *srna = DefRNA.laststruct;
#ifdef DEBUG
#ifndef NDEBUG
if (min > max) {
fprintf(stderr, "%s: \"%s.%s\", min > max.\n",
__func__, srna->identifier, prop->identifier);
@ -1424,8 +1426,8 @@ void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double
DefRNA.error = 1;
}
if (precision < -1 || precision > 10) {
fprintf(stderr, "%s: \"%s.%s\", step outside range.\n",
if (precision < -1 || precision > UI_PRECISION_FLOAT_MAX) {
fprintf(stderr, "%s: \"%s.%s\", precision outside range.\n",
__func__, srna->identifier, prop->identifier);
DefRNA.error = 1;
}
@ -1447,21 +1449,6 @@ void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double
fprop->softmax = (float)max;
fprop->step = (float)step;
fprop->precision = (int)precision;
#if 0 /* handy but annoying */
if (DefRNA.preprocess) {
/* check we're not over PRECISION_FLOAT_MAX */
if (fprop->precision > 6) {
fprintf(stderr, "%s: \"%s.%s\", precision value over maximum.\n",
__func__, srna->identifier, prop->identifier);
DefRNA.error = 1;
}
else if (fprop->precision < 1) {
fprintf(stderr, "%s: \"%s.%s\", precision value under minimum.\n",
__func__, srna->identifier, prop->identifier);
DefRNA.error = 1;
}
}
#endif
break;
}
default: