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>2010-12-06 02:50:55 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-12-06 02:50:55 +0300
commit2f366d1544ecc5618d7190b779ccc75f2f144d0a (patch)
tree699c5b52c7f8768bd46720b1824bee3565e2dff9
parent9668c29ba00ed830109665ea132b6292cdfe9e2a (diff)
use BLI_strnlen rather then strlen when comparing against fixed lengths.
-rw-r--r--source/blender/blenkernel/intern/exotic.c12
-rw-r--r--source/blender/blenkernel/intern/ipo.c2
-rw-r--r--source/blender/blenlib/intern/path_util.c11
-rw-r--r--source/blender/blenloader/intern/readfile.c2
-rw-r--r--source/blender/editors/interface/interface.c12
-rw-r--r--source/blender/editors/interface/interface_handlers.c6
-rw-r--r--source/blender/editors/interface/interface_icons.c2
-rw-r--r--source/blender/editors/physics/physics_fluid.c2
-rw-r--r--source/blender/makesrna/intern/rna_ID.c4
-rw-r--r--source/blender/python/generic/IDProp.c6
10 files changed, 33 insertions, 26 deletions
diff --git a/source/blender/blenkernel/intern/exotic.c b/source/blender/blenkernel/intern/exotic.c
index c16d566c7c5..51fd5e1e4c6 100644
--- a/source/blender/blenkernel/intern/exotic.c
+++ b/source/blender/blenkernel/intern/exotic.c
@@ -1171,10 +1171,10 @@ static void dxf_get_mesh(Scene *scene, Mesh** m, Object** o, int noob)
*o = add_object(scene, OB_MESH);
ob = *o;
- if (strlen(entname)) new_id(&G.main->object, (ID *)ob, entname);
- else if (strlen(layname)) new_id(&G.main->object, (ID *)ob, layname);
+ if (entname[0]) new_id(&G.main->object, (ID *)ob, entname);
+ else if (layname[0]) new_id(&G.main->object, (ID *)ob, layname);
- if (strlen(layname)) ob->lay= dxf_get_layer_num(scene, layname);
+ if (layname[0]) ob->lay= dxf_get_layer_num(scene, layname);
else ob->lay= scene->lay;
// not nice i know... but add_object() sets active base, which needs layer setting too (ton)
scene->basact->lay= ob->lay;
@@ -1193,8 +1193,8 @@ static void dxf_get_mesh(Scene *scene, Mesh** m, Object** o, int noob)
((ID *)me)->us=0;
- if (strlen(entname)) new_id(&G.main->mesh, (ID *)me, entname);
- else if (strlen(layname)) new_id(&G.main->mesh, (ID *)me, layname);
+ if (entname[0]) new_id(&G.main->mesh, (ID *)me, entname);
+ else if (layname[0]) new_id(&G.main->mesh, (ID *)me, layname);
vcenter = zerovec;
}
@@ -2395,7 +2395,7 @@ static void dxf_read(Scene *scene, const char *filename)
I leave it commented out here as warning (ton) */
//for (i=0; i<ob->totcol; i++) ob->mat[i]= ((Mesh*)ob->data)->mat[i];
- if (strlen(layname)) ob->lay= dxf_get_layer_num(scene, layname);
+ if (layname[0]) ob->lay= dxf_get_layer_num(scene, layname);
else ob->lay= scene->lay;
/* link to scene */
diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c
index 7a32562d3d7..5be8bda4cd9 100644
--- a/source/blender/blenkernel/intern/ipo.c
+++ b/source/blender/blenkernel/intern/ipo.c
@@ -1197,7 +1197,7 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve *
fcurve= fcu;
/* set path */
- fcurve->rna_path= BLI_strdupn(abp->path, strlen(abp->path));
+ fcurve->rna_path= BLI_strdup(abp->path);
fcurve->array_index= abp->array_index;
/* convert keyframes
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 9be0690d95a..4cbd93ce0a1 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -418,8 +418,8 @@ void BLI_path_rel(char *file, const char *relfile)
/* also bail out if relative path is not set */
if (relfile[0] == 0) return;
-#ifdef WIN32
- if (strlen(relfile) > 2 && relfile[1] != ':') {
+#ifdef WIN32
+ if (BLI_strnlen(relfile, 3) > 2 && relfile[1] != ':') {
char* ptemp;
/* fix missing volume name in relative base,
can happen with old recent-files.txt files */
@@ -433,7 +433,7 @@ void BLI_path_rel(char *file, const char *relfile)
BLI_strncpy(temp, relfile, FILE_MAXDIR + FILE_MAXFILE);
}
- if (strlen(file) > 2) {
+ if (BLI_strnlen(file, 3) > 2) {
if ( temp[1] == ':' && file[1] == ':' && temp[0] != file[0] )
return;
}
@@ -1181,8 +1181,9 @@ void BLI_setenv_if_new(const char *env, const char* val)
void BLI_clean(char *path)
{
if(path==0) return;
+
#ifdef WIN32
- if(path && strlen(path)>2) {
+ if(path && BLI_strnlen(path, 3) > 2) {
BLI_char_switch(path+2, '/', '\\');
}
#else
@@ -1271,7 +1272,7 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir,
}
#ifdef WIN32
else {
- if (strlen(dir) >= 2 && dir[1] == ':' ) {
+ if (BLI_strnlen(dir, 3) >= 2 && dir[1] == ':' ) {
BLI_strncpy(string, dir, 3);
dir += 2;
}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index aeeced27a92..20ef7f04daf 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -9492,7 +9492,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
for(act= ob->actuators.first; act; act= act->next) {
if (act->type == ACT_MESSAGE) {
bMessageActuator *msgAct = (bMessageActuator *) act->data;
- if (strlen(msgAct->toPropName) > 2) {
+ if (BLI_strnlen(msgAct->toPropName, 3) > 2) {
/* strip first 2 chars, would have only worked if these were OB anyway */
memmove( msgAct->toPropName, msgAct->toPropName+2, sizeof(msgAct->toPropName)-2 );
} else {
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index b62a76ee14a..ab0ee09fb4e 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -2357,7 +2357,7 @@ for float buttons:
static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str, short x1, short y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip)
{
uiBut *but;
- short slen;
+ int slen;
if(type & BUTPOIN) { /* a pointer is required */
if(poin==NULL)
@@ -2374,14 +2374,16 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str,
but->iconadd=0;
but->retval= retval;
- if( strlen(str)>=UI_MAX_NAME_STR-1 ) {
- but->str= MEM_callocN( strlen(str)+2, "uiDefBut");
- strcpy(but->str, str);
+
+ slen= strlen(str);
+ if(slen >= UI_MAX_NAME_STR-1) {
+ but->str= MEM_mallocN(slen+2, "ui_def_but str"); /* why +2 ? */
}
else {
but->str= but->strdata;
- strcpy(but->str, str);
}
+ memcpy(but->str, str, slen+1);
+
but->x1= x1;
but->y1= y1;
but->x2= (x1+x2);
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 35aa351dc20..1e963e37fd2 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -1316,10 +1316,11 @@ static void ui_textedit_move(uiBut *but, uiHandleButtonData *data, int direction
} else {
if(select) {
/* make a selection, starting from the cursor position */
+ int tlen;
but->selsta = but->pos;
but->pos++;
- if(but->pos>strlen(str)) but->pos= strlen(str);
+ if(but->pos > (tlen= strlen(str))) but->pos= tlen;
but->selend = but->pos;
} else if(jump) {
@@ -1331,8 +1332,9 @@ static void ui_textedit_move(uiBut *but, uiHandleButtonData *data, int direction
if(test_special_char(str[but->pos])) break;
}
} else {
+ int tlen;
but->pos++;
- if(but->pos>strlen(str)) but->pos= strlen(str);
+ if(but->pos > (tlen= strlen(str))) but->pos= tlen;
}
}
}
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 8533e5ba893..cf1a90137af 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -507,7 +507,7 @@ static void init_internal_icons(void)
int x, y, icontype;
char iconfilestr[FILE_MAXDIR+FILE_MAXFILE];
- if ((btheme!=NULL) && (strlen(btheme->tui.iconfile) > 0)) {
+ if ((btheme!=NULL) && btheme->tui.iconfile[0]) {
char *datadir= BLI_get_folder(BLENDER_DATAFILES, NULL);
if (datadir) {
BLI_make_file_string("/", iconfilestr, datadir, btheme->tui.iconfile);
diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c
index 1801116fe01..da8e7e063f4 100644
--- a/source/blender/editors/physics/physics_fluid.c
+++ b/source/blender/editors/physics/physics_fluid.c
@@ -665,7 +665,7 @@ static int fluid_init_filepaths(Object *fsDomain, char *targetDir, char *targetF
// invalid dir, reset to current/previous
strcpy(blendDir, G.main->name);
BLI_splitdirstring(blendDir, blendFile);
- if(strlen(blendFile)>6){
+ if(BLI_strnlen(blendFile, 7) > 6){
int len = strlen(blendFile);
if( (blendFile[len-6]=='.')&& (blendFile[len-5]=='b')&& (blendFile[len-4]=='l')&&
(blendFile[len-3]=='e')&& (blendFile[len-2]=='n')&& (blendFile[len-1]=='d') ){
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index 63a2c5d41d4..076669fc1ec 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -223,8 +223,8 @@ StructRNA *rna_IDPropertyGroup_register(const bContext *C, ReportList *reports,
* just a char pointer, but take care here, also be careful that python
* owns the string pointer which it could potentually free while blender
* is running. */
- if(strlen(identifier) >= sizeof(((IDProperty *)NULL)->name)) {
- BKE_reportf(reports, RPT_ERROR, "registering id property class: '%s' is too long, maximum length is %d.", identifier, (int)sizeof(((IDProperty *)NULL)->name));
+ if(BLI_strnlen(identifier, MAX_IDPROP_NAME) == MAX_IDPROP_NAME) {
+ BKE_reportf(reports, RPT_ERROR, "registering id property class: '%s' is too long, maximum length is " STRINGIFY(MAX_IDPROP_NAME) ".", identifier);
return NULL;
}
diff --git a/source/blender/python/generic/IDProp.c b/source/blender/python/generic/IDProp.c
index 1346325e892..cb98ed0fd6b 100644
--- a/source/blender/python/generic/IDProp.c
+++ b/source/blender/python/generic/IDProp.c
@@ -23,9 +23,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+#include "IDProp.h"
+
#include "BKE_idprop.h"
#include "BKE_utildefines.h"
-#include "IDProp.h"
+#include "BLI_string.h"
#include "MEM_guardedalloc.h"
#define USE_STRING_COERCE
@@ -192,7 +194,7 @@ static int BPy_IDGroup_SetName(BPy_IDProperty *self, PyObject *value, void *UNUS
}
st = _PyUnicode_AsString(value);
- if (strlen(st) >= MAX_IDPROP_NAME) {
+ if (BLI_strnlen(st, MAX_IDPROP_NAME) == MAX_IDPROP_NAME) {
PyErr_SetString(PyExc_TypeError, "string length cannot exceed 31 characters!");
return -1;
}