[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43287] trunk/blender/source/blender: use BLI_strncpy and BLI_snprintf when the size of the string is known.

Campbell Barton ideasman42 at gmail.com
Wed Jan 11 13:33:51 CET 2012


Revision: 43287
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43287
Author:   campbellbarton
Date:     2012-01-11 12:33:51 +0000 (Wed, 11 Jan 2012)
Log Message:
-----------
use BLI_strncpy and BLI_snprintf when the size of the string is known.

fix for sequencer unique naming which was missed with string length update.

Modified Paths:
--------------
    trunk/blender/source/blender/blenfont/BLF_api.h
    trunk/blender/source/blender/blenkernel/intern/boids.c
    trunk/blender/source/blender/blenkernel/intern/deform.c
    trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c
    trunk/blender/source/blender/blenkernel/intern/image.c
    trunk/blender/source/blender/blenkernel/intern/ipo.c
    trunk/blender/source/blender/blenkernel/intern/material.c
    trunk/blender/source/blender/blenkernel/intern/packedFile.c
    trunk/blender/source/blender/blenkernel/intern/particle.c
    trunk/blender/source/blender/blenkernel/intern/pointcache.c
    trunk/blender/source/blender/blenkernel/intern/property.c
    trunk/blender/source/blender/blenkernel/intern/seqeffects.c
    trunk/blender/source/blender/blenkernel/intern/sequencer.c
    trunk/blender/source/blender/blenkernel/intern/texture.c
    trunk/blender/source/blender/blenkernel/intern/tracking.c
    trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c
    trunk/blender/source/blender/blenlib/intern/path_util.c
    trunk/blender/source/blender/blenlib/intern/storage.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/editors/animation/anim_ipo_utils.c
    trunk/blender/source/blender/editors/armature/editarmature_retarget.c
    trunk/blender/source/blender/editors/armature/meshlaplacian.c
    trunk/blender/source/blender/editors/armature/poseSlide.c
    trunk/blender/source/blender/editors/armature/poselib.c
    trunk/blender/source/blender/editors/armature/reeb.c
    trunk/blender/source/blender/editors/curve/editcurve.c
    trunk/blender/source/blender/editors/gpencil/gpencil_buttons.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/view2d.c
    trunk/blender/source/blender/editors/physics/physics_fluid.c
    trunk/blender/source/blender/editors/screen/area.c
    trunk/blender/source/blender/editors/space_file/file_draw.c
    trunk/blender/source/blender/editors/space_file/filelist.c
    trunk/blender/source/blender/editors/space_graph/graph_buttons.c
    trunk/blender/source/blender/editors/space_image/image_buttons.c
    trunk/blender/source/blender/editors/space_image/image_draw.c
    trunk/blender/source/blender/editors/space_info/info_ops.c
    trunk/blender/source/blender/editors/space_logic/logic_window.c
    trunk/blender/source/blender/editors/space_nla/nla_draw.c
    trunk/blender/source/blender/editors/space_outliner/outliner_edit.c
    trunk/blender/source/blender/editors/space_text/text_draw.c
    trunk/blender/source/blender/editors/space_view3d/drawobject.c
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
    trunk/blender/source/blender/editors/transform/transform_constraints.c
    trunk/blender/source/blender/editors/util/ed_util.c
    trunk/blender/source/blender/editors/util/numinput.c
    trunk/blender/source/blender/editors/uvedit/uvedit_unwrap_ops.c
    trunk/blender/source/blender/gpu/intern/gpu_material.c
    trunk/blender/source/blender/imbuf/intern/anim_movie.c
    trunk/blender/source/blender/nodes/composite/node_composite_tree.c
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: trunk/blender/source/blender/blenfont/BLF_api.h
===================================================================
--- trunk/blender/source/blender/blenfont/BLF_api.h	2012-01-11 12:28:31 UTC (rev 43286)
+++ trunk/blender/source/blender/blenfont/BLF_api.h	2012-01-11 12:33:51 UTC (rev 43287)
@@ -198,6 +198,8 @@
 #define BLF_MATRIX (1<<4)
 #define BLF_ASPECT (1<<5)
 
+#define BLF_DRAW_STR_DUMMY_MAX 1024
+
 // XXX, bad design
 extern int blf_mono_font;
 extern int blf_mono_font_render; // dont mess drawing with render threads.

Modified: trunk/blender/source/blender/blenkernel/intern/boids.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/boids.c	2012-01-11 12:28:31 UTC (rev 43286)
+++ trunk/blender/source/blender/blenkernel/intern/boids.c	2012-01-11 12:33:51 UTC (rev 43287)
@@ -1503,7 +1503,7 @@
 
 	state->id = boids->last_state_id++;
 	if(state->id)
-		sprintf(state->name, "State %i", state->id);
+		BLI_snprintf(state->name, sizeof(state->name), "State %i", state->id);
 	else
 		strcpy(state->name, "State");
 

Modified: trunk/blender/source/blender/blenkernel/intern/deform.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/deform.c	2012-01-11 12:28:31 UTC (rev 43286)
+++ trunk/blender/source/blender/blenkernel/intern/deform.c	2012-01-11 12:33:51 UTC (rev 43287)
@@ -476,22 +476,22 @@
 		switch(name[0]) {
 			case 'l':
 				strcpy(replace, "r");
-				strcpy(suffix, name+1);
+				BLI_strncpy(suffix, name+1, sizeof(suffix));
 				prefix[0]= 0;
 				break;
 			case 'r':
 				strcpy(replace, "l");
-				strcpy(suffix, name+1);
+				BLI_strncpy(suffix, name+1, sizeof(suffix));
 				prefix[0]= 0;
 				break;
 			case 'L':
 				strcpy(replace, "R");
-				strcpy(suffix, name+1);
+				BLI_strncpy(suffix, name+1, sizeof(suffix));
 				prefix[0]= 0;
 				break;
 			case 'R':
 				strcpy(replace, "L");
-				strcpy(suffix, name+1);
+				BLI_strncpy(suffix, name+1, sizeof(suffix));
 				prefix[0]= 0;
 				break;
 		}
@@ -501,29 +501,29 @@
 		index = BLI_strcasestr(prefix, "right");
 		if (index==prefix || index==prefix+len-5) {
 			if (index[0]=='r')
-				strcpy (replace, "left");
+				strcpy(replace, "left");
 			else {
 				if (index[1]=='I')
-					strcpy (replace, "LEFT");
+					strcpy(replace, "LEFT");
 				else
-					strcpy (replace, "Left");
+					strcpy(replace, "Left");
 			}
 			*index= 0;
-			strcpy (suffix, index+5);
+			BLI_strncpy(suffix, index+5, sizeof(suffix));
 		}
 		else {
 			index = BLI_strcasestr(prefix, "left");
 			if (index==prefix || index==prefix+len-4) {
 				if (index[0]=='l')
-					strcpy (replace, "right");
+					strcpy(replace, "right");
 				else {
 					if (index[1]=='E')
-						strcpy (replace, "RIGHT");
+						strcpy(replace, "RIGHT");
 					else
-						strcpy (replace, "Right");
+						strcpy(replace, "Right");
 				}
 				*index= 0;
-				strcpy (suffix, index+4);
+				BLI_strncpy(suffix, index + 4, sizeof(suffix));
 			}
 		}
 	}

Modified: trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c	2012-01-11 12:28:31 UTC (rev 43286)
+++ trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c	2012-01-11 12:33:51 UTC (rev 43287)
@@ -361,8 +361,8 @@
 		surface->depth_clamp = 1.0f;
 	}
 	else {
-		sprintf(surface->output_name, "dp_");
-		strcpy(surface->output_name2,surface->output_name);
+		strcpy(surface->output_name, "dp_");
+		strcpy(surface->output_name2, surface->output_name);
 		surface->flags &= ~MOD_DPAINT_ANTIALIAS;
 		surface->depth_clamp = 0.0f;
 	}

Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c	2012-01-11 12:28:31 UTC (rev 43286)
+++ trunk/blender/source/blender/blenkernel/intern/image.c	2012-01-11 12:33:51 UTC (rev 43287)
@@ -1168,7 +1168,7 @@
 		char *name = scene_find_last_marker_name(scene, CFRA);
 
 		if (name)	BLI_strncpy(text, name, sizeof(text));
-		else 		strcpy(text, "<none>");
+		else 		BLI_strncpy(text, "<none>", sizeof(text));
 
 		BLI_snprintf(stamp_data->marker, sizeof(stamp_data->marker), do_prefix ? "Marker %s":"%s", text);
 	} else {
@@ -1224,7 +1224,7 @@
 		if (camera && camera->type == OB_CAMERA) {
 			BLI_snprintf(text, sizeof(text), "%.2f", ((Camera *)camera->data)->lens);
 		}
-		else 		strcpy(text, "<none>");
+		else 		BLI_strncpy(text, "<none>", sizeof(text));
 
 		BLI_snprintf(stamp_data->cameralens, sizeof(stamp_data->cameralens), do_prefix ? "Lens %s":"%s", text);
 	} else {
@@ -1241,7 +1241,7 @@
 		Sequence *seq= seq_foreground_frame_get(scene, scene->r.cfra);
 	
 		if (seq)	BLI_strncpy(text, seq->name+2, sizeof(text));
-		else 		strcpy(text, "<none>");
+		else 		BLI_strncpy(text, "<none>", sizeof(text));
 
 		BLI_snprintf(stamp_data->strip, sizeof(stamp_data->strip), do_prefix ? "Strip %s":"%s", text);
 	} else {

Modified: trunk/blender/source/blender/blenkernel/intern/ipo.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/ipo.c	2012-01-11 12:28:31 UTC (rev 43286)
+++ trunk/blender/source/blender/blenkernel/intern/ipo.c	2012-01-11 12:33:51 UTC (rev 43287)
@@ -328,9 +328,9 @@
 	/* block will be attached to ID_KE block, and setting that we alter is the 'value' (which sets keyblock.curval) */
 	// XXX adrcode 0 was dummy 'speed' curve 
 	if (adrcode == 0) 
-		sprintf(buf, "speed");
+		strcpy(buf, "speed");
 	else
-		sprintf(buf, "key_blocks[%d].value", adrcode);
+		BLI_snprintf(buf, sizeof(buf), "key_blocks[%d].value", adrcode);
 	return buf;
 }
 
@@ -915,7 +915,7 @@
 	/* note, strings are not escapted and they should be! */
 	if ((actname && actname[0]) && (constname && constname[0])) {
 		/* Constraint in Pose-Channel */
-		sprintf(buf, "pose.bones[\"%s\"].constraints[\"%s\"]", actname, constname);
+		BLI_snprintf(buf, sizeof(buf), "pose.bones[\"%s\"].constraints[\"%s\"]", actname, constname);
 	}
 	else if (actname && actname[0]) {
 		if ((blocktype == ID_OB) && strcmp(actname, "Object")==0) {
@@ -928,16 +928,16 @@
 		}
 		else {
 			/* Pose-Channel */
-			sprintf(buf, "pose.bones[\"%s\"]", actname);
+			BLI_snprintf(buf, sizeof(buf), "pose.bones[\"%s\"]", actname);
 		}
 	}
 	else if (constname && constname[0]) {
 		/* Constraint in Object */
-		sprintf(buf, "constraints[\"%s\"]", constname);
+		BLI_snprintf(buf, sizeof(buf), "constraints[\"%s\"]", constname);
 	}
 	else if (seq) {
 		/* Sequence names in Scene */
-		sprintf(buf, "sequence_editor.sequences_all[\"%s\"]", seq->name+2);
+		BLI_snprintf(buf, sizeof(buf), "sequence_editor.sequences_all[\"%s\"]", seq->name+2);
 	}
 	else {
 		buf[0]= '\0'; /* empty string */
@@ -954,7 +954,7 @@
 	
 	/* if there was no array index pointer provided, add it to the path */
 	if (array_index == NULL) {
-		sprintf(buf, "[\"%d\"]", dummy_index);
+		BLI_snprintf(buf, sizeof(buf), "[\"%d\"]", dummy_index);
 		BLI_dynstr_append(path, buf);
 	}
 	

Modified: trunk/blender/source/blender/blenkernel/intern/material.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/material.c	2012-01-11 12:28:31 UTC (rev 43286)
+++ trunk/blender/source/blender/blenkernel/intern/material.c	2012-01-11 12:33:51 UTC (rev 43287)
@@ -51,6 +51,7 @@
 #include "BLI_listbase.h"		
 #include "BLI_utildefines.h"
 #include "BLI_bpath.h"
+#include "BLI_string.h"
 
 #include "BKE_animsys.h"
 #include "BKE_displist.h"
@@ -1614,7 +1615,7 @@
 	int digits = integer_getdigits(flag);
 	/* clamp the old name, remove the MA prefix and add the .TF.flag suffix
 	e.g. matname = "MALoooooooooooooongName"; newname = "Loooooooooooooon.TF.2" */
-	sprintf(newname, "%.*s.TF.%0*d", MAX_ID_NAME-(digits+5), matname, digits, flag);
+	BLI_snprintf(newname, MAX_ID_NAME, "%.*s.TF.%0*d", MAX_ID_NAME-(digits+5), matname, digits, flag);
 }
 
 /* returns -1 if no match */
@@ -1661,8 +1662,8 @@
 	short mat_nr= -1;
 	
 	/* new material, the name uses the flag*/
-	sprintf(idname, "MAMaterial.TF.%0*d", integer_getdigits(flag), flag);
-	
+	BLI_snprintf(idname, sizeof(idname), "MAMaterial.TF.%0*d", integer_getdigits(flag), flag);
+
 	if ((ma= BLI_findstring(&main->mat, idname+2, offsetof(ID, name)+2))) {
 		mat_nr= mesh_getmaterialnumber(me, ma);
 		/* assign the material to the mesh */

Modified: trunk/blender/source/blender/blenkernel/intern/packedFile.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/packedFile.c	2012-01-11 12:28:31 UTC (rev 43286)
+++ trunk/blender/source/blender/blenkernel/intern/packedFile.c	2012-01-11 12:33:51 UTC (rev 43287)
@@ -251,7 +251,7 @@
 	
 	if (fop_exists(name)) {
 		for (number = 1; number <= 999; number++) {
-			sprintf(tempname, "%s.%03d", name, number);
+			BLI_snprintf(tempname, sizeof(tempname), "%s.%03d", name, number);
 			if (! fop_exists(tempname)) {
 				break;
 			}

Modified: trunk/blender/source/blender/blenkernel/intern/particle.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle.c	2012-01-11 12:28:31 UTC (rev 43286)
+++ trunk/blender/source/blender/blenkernel/intern/particle.c	2012-01-11 12:33:51 UTC (rev 43287)
@@ -3409,14 +3409,14 @@
 	psys->part = psys_new_settings("ParticleSettings", NULL);
 
 	if(BLI_countlist(&ob->particlesystem)>1)
-		sprintf(psys->name, "ParticleSystem %i", BLI_countlist(&ob->particlesystem));
+		BLI_snprintf(psys->name, sizeof(psys->name), "ParticleSystem %i", BLI_countlist(&ob->particlesystem));
 	else
 		strcpy(psys->name, "ParticleSystem");
 
 	md= modifier_new(eModifierType_ParticleSystem);
 
 	if(name)	BLI_strncpy(md->name, name, sizeof(md->name));
-	else		sprintf(md->name, "ParticleSystem %i", BLI_countlist(&ob->particlesystem));
+	else		BLI_snprintf(md->name, sizeof(md->name), "ParticleSystem %i", BLI_countlist(&ob->particlesystem));
 	modifier_unique_name(&ob->modifiers, md);
 
 	psmd= (ParticleSystemModifierData*) md;

Modified: trunk/blender/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/pointcache.c	2012-01-11 12:28:31 UTC (rev 43286)

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-blender-cvs mailing list