[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40578] trunk/blender: use BLI_snprintf rather than sprintf for interface functions

Campbell Barton ideasman42 at gmail.com
Mon Sep 26 18:53:05 CEST 2011


Revision: 40578
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40578
Author:   campbellbarton
Date:     2011-09-26 16:53:04 +0000 (Mon, 26 Sep 2011)
Log Message:
-----------
use BLI_snprintf rather than sprintf for interface functions

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/properties_game.py
    trunk/blender/release/scripts/startup/bl_ui/properties_particle.py
    trunk/blender/source/blender/editors/interface/interface.c
    trunk/blender/source/blender/editors/interface/interface_draw.c
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/editors/interface/interface_layout.c
    trunk/blender/source/blender/editors/interface/interface_regions.c
    trunk/blender/source/blender/editors/interface/interface_style.c
    trunk/blender/source/blender/editors/interface/interface_templates.c
    trunk/blender/source/blender/editors/interface/interface_utils.c

Modified: trunk/blender/release/scripts/startup/bl_ui/properties_game.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/properties_game.py	2011-09-26 15:49:03 UTC (rev 40577)
+++ trunk/blender/release/scripts/startup/bl_ui/properties_game.py	2011-09-26 16:53:04 UTC (rev 40578)
@@ -204,7 +204,7 @@
     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

Modified: trunk/blender/release/scripts/startup/bl_ui/properties_particle.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/properties_particle.py	2011-09-26 15:49:03 UTC (rev 40577)
+++ trunk/blender/release/scripts/startup/bl_ui/properties_particle.py	2011-09-26 16:53:04 UTC (rev 40578)
@@ -988,7 +988,7 @@
         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):

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2011-09-26 15:49:03 UTC (rev 40577)
+++ trunk/blender/source/blender/editors/interface/interface.c	2011-09-26 16:53:04 UTC (rev 40578)
@@ -2143,8 +2143,8 @@
 		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 @@
 			}
 		}
 		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) {

Modified: trunk/blender/source/blender/editors/interface/interface_draw.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_draw.c	2011-09-26 15:49:03 UTC (rev 40577)
+++ trunk/blender/source/blender/editors/interface/interface_draw.c	2011-09-26 16:53:04 UTC (rev 40578)
@@ -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 @@
 	/* 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);

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2011-09-26 15:49:03 UTC (rev 40577)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2011-09-26 16:53:04 UTC (rev 40578)
@@ -1113,9 +1113,9 @@
 		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 @@
 		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 @@
 		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);

Modified: trunk/blender/source/blender/editors/interface/interface_layout.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_layout.c	2011-09-26 15:49:03 UTC (rev 40577)
+++ trunk/blender/source/blender/editors/interface/interface_layout.c	2011-09-26 16:53:04 UTC (rev 40578)
@@ -1219,7 +1219,7 @@
 #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);

Modified: trunk/blender/source/blender/editors/interface/interface_regions.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_regions.c	2011-09-26 15:49:03 UTC (rev 40577)
+++ trunk/blender/source/blender/editors/interface/interface_regions.c	2011-09-26 16:53:04 UTC (rev 40578)
@@ -230,9 +230,11 @@
 	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 @@
 			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 @@
 	
 	/* 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 @@
 		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 @@
 		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 @@
 	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 @@
 	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);

Modified: trunk/blender/source/blender/editors/interface/interface_style.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_style.c	2011-09-26 15:49:03 UTC (rev 40577)
+++ trunk/blender/source/blender/editors/interface/interface_style.c	2011-09-26 16:53:04 UTC (rev 40578)
@@ -315,7 +315,7 @@
 		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;
 	}
 	

Modified: trunk/blender/source/blender/editors/interface/interface_templates.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_templates.c	2011-09-26 15:49:03 UTC (rev 40577)
+++ trunk/blender/source/blender/editors/interface/interface_templates.c	2011-09-26 16:53:04 UTC (rev 40578)
@@ -412,7 +412,7 @@
 		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 @@
 		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 @@

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list