Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-08-13 21:05:27 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-08-13 21:05:27 +0400
commit52a6a07d67f48c6c3465cbaf156bf8057755e1bc (patch)
treee10f280438fc1d2f14765bd918e54d3110d08ad8 /source/blender/editors/interface/interface.c
parente8d9e0823ee73e3c3fdd596fd3945abec40d21c1 (diff)
added string max length option for unit functions bUnit_AsString and bUnit_ReplaceString
Diffstat (limited to 'source/blender/editors/interface/interface.c')
-rw-r--r--source/blender/editors/interface/interface.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index bbdaad5fd5d..ac26fe86364 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -1339,7 +1339,7 @@ static double ui_get_but_scale_unit(uiBut *but, double value)
}
}
-static void ui_get_but_string_unit(uiBut *but, char *str, double value, int pad)
+static void ui_get_but_string_unit(uiBut *but, char *str, int len_max, double value, int pad)
{
Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
int do_split= scene->unit.flag & USER_UNIT_OPT_SPLIT;
@@ -1352,7 +1352,7 @@ static void ui_get_but_string_unit(uiBut *but, char *str, double value, int pad)
if(precission>4) precission= 4;
else if(precission==0) precission= 2;
- bUnit_AsString(str, ui_get_but_scale_unit(but, value), precission, scene->unit.system, unit_type, do_split, pad);
+ bUnit_AsString(str, len_max, ui_get_but_scale_unit(but, value), precission, scene->unit.system, unit_type, do_split, pad);
}
static float ui_get_but_step_unit(uiBut *but, double value, float step_default)
@@ -1428,7 +1428,7 @@ void ui_get_but_string(uiBut *but, char *str, int maxlen)
if(ui_is_but_float(but)) {
if(ui_is_but_unit(but)) {
- ui_get_but_string_unit(but, str, value, 0);
+ ui_get_but_string_unit(but, str, maxlen, value, 0);
}
else if(but->a2) { /* amount of digits defined */
if(but->a2==1) BLI_snprintf(str, maxlen, "%.1f", value);
@@ -1505,21 +1505,20 @@ int ui_set_but_string(bContext *C, uiBut *but, const char *str)
#ifndef DISABLE_PYTHON
{
- Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
char str_unit_convert[256];
int unit_type;
-
- if (but->rnaprop)
- RNA_SUBTYPE_UNIT_VALUE(RNA_property_subtype(but->rnaprop));
+ Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
+
+ if(but->rnaprop)
+ unit_type= RNA_SUBTYPE_UNIT_VALUE(RNA_property_subtype(but->rnaprop));
else
unit_type= 0;
-
+
+ BLI_strncpy(str_unit_convert, str, sizeof(str_unit_convert));
+
if(scene->unit.system != USER_UNIT_NONE && unit_type) {
/* ugly, use the draw string to get the value, this could cause problems if it includes some text which resolves to a unit */
- bUnit_ReplaceString(str_unit_convert, (char *)str, but->drawstr, ui_get_but_scale_unit(but, 1.0), scene->unit.system, unit_type);
- }
- else {
- strcpy(str_unit_convert, str);
+ bUnit_ReplaceString(str_unit_convert, sizeof(str_unit_convert), but->drawstr, ui_get_but_scale_unit(but, 1.0), scene->unit.system, unit_type);
}
if(BPY_button_eval(C, str_unit_convert, &value)) {
@@ -1875,9 +1874,9 @@ void ui_check_but(uiBut *but)
else if(value == -FLT_MAX) sprintf(but->drawstr, "%s-inf", but->str);
/* support length type buttons */
else if(ui_is_but_unit(but)) {
- char new_str[256];
- ui_get_but_string_unit(but, new_str, value, TRUE);
- sprintf(but->drawstr, "%s%s", but->str, new_str);
+ char new_str[sizeof(but->drawstr)];
+ ui_get_but_string_unit(but, new_str, sizeof(new_str), value, TRUE);
+ snprintf(but->drawstr, sizeof(but->drawstr), "%s%s", but->str, new_str);
}
else if(but->a2) { /* amount of digits defined */
if(but->a2==1) sprintf(but->drawstr, "%s%.1f", but->str, value);