use BLI_strnlen rather then strlen when comparing against fixed lengths.
authorCampbell Barton <ideasman42@gmail.com>
Sun, 5 Dec 2010 23:50:55 +0000 (23:50 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 5 Dec 2010 23:50:55 +0000 (23:50 +0000)
source/blender/blenkernel/intern/exotic.c
source/blender/blenkernel/intern/ipo.c
source/blender/blenlib/intern/path_util.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_icons.c
source/blender/editors/physics/physics_fluid.c
source/blender/makesrna/intern/rna_ID.c
source/blender/python/generic/IDProp.c

index c16d566..51fd5e1 100644 (file)
@@ -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 */
index 7a32562..5be8bda 100644 (file)
@@ -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 
index 9be0690..4cbd93c 100644 (file)
@@ -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;
                }
index aeeced2..20ef7f0 100644 (file)
@@ -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 {
index b62a76e..ab0ee09 100644 (file)
@@ -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); 
index 35aa351..1e963e3 100644 (file)
@@ -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;
                        }
                }
        }
index 8533e5b..cf1a901 100644 (file)
@@ -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);
index 1801116..da8e7e0 100644 (file)
@@ -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') ){
index 63a2c5d..076669f 100644 (file)
@@ -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;
        }
 
index 1346325..cb98ed0 100644 (file)
  * ***** 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;
        }