use BLI_snprintf rather than sprintf for interface functions
authorCampbell Barton <ideasman42@gmail.com>
Mon, 26 Sep 2011 16:53:04 +0000 (16:53 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 26 Sep 2011 16:53:04 +0000 (16:53 +0000)
release/scripts/startup/bl_ui/properties_game.py
release/scripts/startup/bl_ui/properties_particle.py
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_draw.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_layout.c
source/blender/editors/interface/interface_regions.c
source/blender/editors/interface/interface_style.c
source/blender/editors/interface/interface_templates.c
source/blender/editors/interface/interface_utils.c

index 469c1e6..8cb73d2 100644 (file)
@@ -204,7 +204,7 @@ class PHYSICS_PT_game_obstacles(PhysicsButtonsPanel, Panel):
     def poll(cls, context):
         game = context.object.game
         rd = context.scene.render
-        return (game.physics_type in ('DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC'))  and (rd.engine in cls.COMPAT_ENGINES)
+        return (game.physics_type in {'DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC'}) and (rd.engine in cls.COMPAT_ENGINES)
 
     def draw_header(self, context):
         game = context.active_object.game
index edd5745..eceefc7 100644 (file)
@@ -988,7 +988,7 @@ class PARTICLE_PT_draw(ParticleButtonsPanel, Panel):
         col.label(text="Color:")
         col.prop(part, "draw_color", text="")
         sub = col.row()
-        sub.active = part.draw_color in ('VELOCITY', 'ACCELERATION')
+        sub.active = (part.draw_color in {'VELOCITY', 'ACCELERATION'})
         sub.prop(part, "color_maximum", text="Max")
 
         if (path):
index 8f440f7..49156d3 100644 (file)
@@ -2143,8 +2143,8 @@ void ui_check_but(uiBut *but)
                UI_GET_BUT_VALUE_INIT(but, value)
 
                if(ui_is_but_float(but)) {
-                       if(value == (double) FLT_MAX) sprintf(but->drawstr, "%sinf", but->str);
-                       else if(value == (double) -FLT_MAX) sprintf(but->drawstr, "%s-inf", but->str);
+                       if(value == (double) FLT_MAX) BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%sinf", but->str);
+                       else if(value == (double) -FLT_MAX) BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s-inf", but->str);
                        /* support length type buttons */
                        else if(ui_is_but_unit(but)) {
                                char new_str[sizeof(but->drawstr)];
@@ -2157,7 +2157,7 @@ void ui_check_but(uiBut *but)
                        }
                }
                else {
-                       sprintf(but->drawstr, "%s%d", but->str, (int)value);
+                       BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%d", but->str, (int)value);
                }
                        
                if(but->rnaprop) {
index fd437d2..b65be48 100644 (file)
@@ -39,6 +39,7 @@
 
 #include "BLI_math.h"
 #include "BLI_rect.h"
+#include "BLI_string.h"
 #include "BLI_utildefines.h"
 
 #include "BKE_colortools.h"
@@ -835,7 +836,7 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol),
        /* draw grid lines here */
        for (i=0; i<6; i++) {
                char str[4];
-               sprintf(str,"%-3d",i*20);
+               BLI_snprintf(str, sizeof(str), "%-3d",i*20);
                str[3]='\0';
                fdrawline(rect.xmin+22, yofs+(i/5.f)*h, rect.xmax+1, yofs+(i/5.f)*h);
                BLF_draw_default(rect.xmin+1, yofs-5+(i/5.f)*h, 0, str, sizeof(str)-1);
index e4776cd..568eaf3 100644 (file)
@@ -1113,9 +1113,9 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
                if(but->poin==NULL && but->rnapoin.data==NULL);
                else if(mode=='c') {
                        if(ui_is_but_float(but))
-                               sprintf(buf, "%f", ui_get_but_val(but));
+                               BLI_snprintf(buf, sizeof(buf), "%f", ui_get_but_val(but));
                        else
-                               sprintf(buf, "%d", (int)ui_get_but_val(but));
+                               BLI_snprintf(buf, sizeof(buf), "%d", (int)ui_get_but_val(but));
 
                        WM_clipboard_text_set(buf, 0);
                }
@@ -1136,7 +1136,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
                else if(mode=='c') {
 
                        ui_get_but_vectorf(but, rgb);
-                       sprintf(buf, "[%f, %f, %f]", rgb[0], rgb[1], rgb[2]);
+                       BLI_snprintf(buf, sizeof(buf), "[%f, %f, %f]", rgb[0], rgb[1], rgb[2]);
                        WM_clipboard_text_set(buf, 0);
                        
                }
@@ -4367,7 +4367,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
                PointerRNA ptr_props;
 
                if(but->rnapoin.data && but->rnaprop) {
-                       sprintf(buf, "%s.%s", RNA_struct_identifier(but->rnapoin.type), RNA_property_identifier(but->rnaprop));
+                       BLI_snprintf(buf, sizeof(buf), "%s.%s", RNA_struct_identifier(but->rnapoin.type), RNA_property_identifier(but->rnaprop));
 
                        WM_operator_properties_create(&ptr_props, "WM_OT_doc_view");
                        RNA_string_set(&ptr_props, "doc_id", buf);
index ae66d64..ab07cb4 100644 (file)
@@ -1219,7 +1219,7 @@ static void rna_search_cb(const struct bContext *C, void *arg_but, const char *s
 #if 0          /* this name is used for a string comparison and can't be modified, TODO */
                        name_uiprefix_id(name_ui, id);
 #else
-                       strcpy(name_ui, id->name+2);
+                       BLI_strncpy(name_ui, id->name+2, sizeof(name_ui));
 #endif
                        name= BLI_strdup(name_ui);
                        iconid= ui_id_icon_get((bContext*)C, id, 1);
index 4221f7c..c0d6a07 100644 (file)
@@ -230,9 +230,11 @@ void ui_set_name_menu(uiBut *but, int value)
        int i;
        
        md= decompose_menu_string(but->str);
-       for (i=0; i<md->nitems; i++)
-               if (md->items[i].retval==value)
-                       strcpy(but->drawstr, md->items[i].str);
+       for (i=0; i<md->nitems; i++) {
+               if (md->items[i].retval==value) {
+                       BLI_strncpy(but->drawstr, md->items[i].str, sizeof(but->drawstr));
+               }
+       }
        
        menudata_free(md);
 }
@@ -1798,7 +1800,7 @@ static void ui_update_block_buts_rgb(uiBlock *block, float *rgb)
                        if (rgb_gamma[1] > 1.0f) rgb_gamma[1] = modf(rgb_gamma[1], &intpart);
                        if (rgb_gamma[2] > 1.0f) rgb_gamma[2] = modf(rgb_gamma[2], &intpart);
 
-                       sprintf(col, "%02X%02X%02X", FTOCHAR(rgb_gamma[0]), FTOCHAR(rgb_gamma[1]), FTOCHAR(rgb_gamma[2]));
+                       BLI_snprintf(col, sizeof(col), "%02X%02X%02X", FTOCHAR(rgb_gamma[0]), FTOCHAR(rgb_gamma[1]), FTOCHAR(rgb_gamma[2]));
                        
                        strcpy(bt->poin, col);
                }
@@ -1986,10 +1988,10 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR
        
        /* existence of profile means storage is in linear color space, with display correction */
        if (block->color_profile == BLI_PR_NONE) {
-               sprintf(tip, "Value in Display Color Space");
+               BLI_strncpy(tip, "Value in Display Color Space", sizeof(tip));
                copy_v3_v3(rgb_gamma, rgb);
        } else {
-               sprintf(tip, "Value in Linear RGB Color Space");
+               BLI_strncpy(tip, "Value in Linear RGB Color Space", sizeof(tip));
                /* make an sRGB version, for Hex code */
                linearrgb_to_srgb_v3_v3(rgb_gamma, rgb);
        }
@@ -2058,7 +2060,7 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR
                rgb[3]= 1.0f;
        }
 
-       sprintf(hexcol, "%02X%02X%02X", FTOCHAR(rgb_gamma[0]), FTOCHAR(rgb_gamma[1]), FTOCHAR(rgb_gamma[2]));
+       BLI_snprintf(hexcol, sizeof(hexcol), "%02X%02X%02X", FTOCHAR(rgb_gamma[0]), FTOCHAR(rgb_gamma[1]), FTOCHAR(rgb_gamma[2]));
 
        bt= uiDefBut(block, TEX, 0, "Hex: ", 0, -60, butwidth, UI_UNIT_Y, hexcol, 0, 8, 0, 0, "Hex triplet for color (#RRGGBB)");
        uiButSetFunc(bt, do_hex_rna_cb, bt, hexcol);
@@ -2369,7 +2371,7 @@ uiPopupMenu *uiPupMenuBegin(bContext *C, const char *title, int icon)
                char titlestr[256];
                
                if(icon) {
-                       sprintf(titlestr, " %s", title);
+                       BLI_snprintf(titlestr, sizeof(titlestr), " %s", title);
                        uiDefIconTextBut(pup->block, LABEL, 0, icon, titlestr, 0, 0, 200, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
                }
                else {
@@ -2467,7 +2469,7 @@ void uiPupMenuOkee(bContext *C, const char *opname, const char *str, ...)
        va_list ap;
        char titlestr[256];
 
-       sprintf(titlestr, "OK? %%i%d", ICON_QUESTION);
+       BLI_snprintf(titlestr, sizeof(titlestr), "OK? %%i%d", ICON_QUESTION);
 
        va_start(ap, str);
        vconfirm_opname(C, opname, titlestr, str, ap);
@@ -2507,9 +2509,9 @@ void uiPupMenuError(bContext *C, const char *str, ...)
        char nfmt[256];
        char titlestr[256];
 
-       sprintf(titlestr, "Error %%i%d", ICON_ERROR);
+       BLI_snprintf(titlestr, sizeof(titlestr), "Error %%i%d", ICON_ERROR);
 
-       sprintf(nfmt, "%s", str);
+       BLI_strncpy(nfmt, str, sizeof(nfmt));
 
        va_start(ap, str);
        vconfirm_opname(C, NULL, titlestr, nfmt, ap);
index 2a183e3..3009d4f 100644 (file)
@@ -315,7 +315,7 @@ void uiStyleInit(void)
                font= MEM_callocN(sizeof(uiFont), "ui font");
                BLI_addtail(&U.uifonts, font);
                
-               strcpy(font->filename, "default");
+               BLI_strncpy(font->filename, "default", sizeof(font->filename));
                font->uifont_id= UIFONT_DEFAULT;
        }
        
index bec9e6a..a4622f5 100644 (file)
@@ -412,7 +412,7 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str
                if(id->us > 1) {
                        char str[32];
 
-                       sprintf(str, "%d", id->us);
+                       BLI_snprintf(str, sizeof(str), "%d", id->us);
 
                        but= uiDefBut(block, BUT, 0, str, 0,0,UI_UNIT_X + ((id->us < 10) ? 0:10), UI_UNIT_Y, NULL, 0, 0, 0, 0,
                                                UI_translate_do_tooltip(_("Displays number of users of this data. Click to make a single-user copy")));
@@ -724,7 +724,7 @@ static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob, Modif
                block= uiLayoutGetBlock(row);
                /* VIRTUAL MODIFIER */
                // XXX this is not used now, since these cannot be accessed via RNA
-               sprintf(str, "%s parent deform", md->name);
+               BLI_snprintf(str, sizeof(str), "%s parent deform", md->name);
                uiDefBut(block, LABEL, 0, str, 0, 0, 185, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, "Modifier name"); 
                
                but = uiDefBut(block, BUT, 0, UI_translate_do_iface(N_("Make Real")), 0, 0, 80, 16, NULL, 0.0, 0.0, 0.0, 0.0,
@@ -959,13 +959,10 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con)
        cti= constraint_get_typeinfo(con);
        if (cti == NULL) {
                /* exception for 'Null' constraint - it doesn't have constraint typeinfo! */
-               if (con->type == CONSTRAINT_TYPE_NULL)
-                       strcpy(typestr, "Null");
-               else
-                       strcpy(typestr, "Unknown");
+               BLI_strncpy(typestr, (con->type == CONSTRAINT_TYPE_NULL) ? "Null" : "Unknown", sizeof(typestr));
        }
        else
-               strcpy(typestr, cti->name);
+               BLI_strncpy(typestr, cti->name, sizeof(typestr));
                
        /* determine whether constraint is proxy protected or not */
        if (proxylocked_constraints_owner(ob, pchan))
@@ -2112,7 +2109,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe
                        manode= give_node_material(ma);
                        if(manode) {
                                char str[MAX_ID_NAME + 12];
-                               sprintf(str, "Node %s", manode->id.name+2);
+                               BLI_snprintf(str, sizeof(str), "Node %s", manode->id.name+2);
                                uiItemL(sub, str, ui_id_icon_get(C, &manode->id, 1));
                        }
                        else if(ma->use_nodes) {
@@ -2281,7 +2278,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *
                        uiItemL(row, "", ICON_NONE);
 
                /* next/prev button */
-               sprintf(str, "%d :", i);
+               BLI_snprintf(str, sizeof(str), "%d :", i);
                but= uiDefIconTextButR_prop(block, NUM, 0, 0, str, 0,0,UI_UNIT_X*5,UI_UNIT_Y, activeptr, activeprop, 0, 0, 0, 0, 0, "");
                if(i == 0)
                        uiButSetFlag(but, UI_BUT_DISABLED);
index a49060e..206ecba 100644 (file)
@@ -36,6 +36,7 @@
 #include "DNA_object_types.h"
 
 #include "BLI_utildefines.h"
+#include "BLI_string.h"
 
 #include "BLF_translation.h"
 
@@ -116,7 +117,7 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind
                }
                case PROP_COLLECTION: {
                        char text[256];
-                       sprintf(text, UI_translate_do_iface(N_("%d items")), RNA_property_collection_length(ptr, prop));
+                       BLI_snprintf(text, sizeof(text), UI_translate_do_iface(N_("%d items")), RNA_property_collection_length(ptr, prop));
                        but= uiDefBut(block, LABEL, 0, text, x1, y1, x2, y2, NULL, 0, 0, 0, 0, NULL);
                        uiButSetFlag(but, UI_BUT_DISABLED);
                        break;