replace BLI_strncpy with BLI_strncpy_utf8 where input isnt ensured to be valid.
authorCampbell Barton <ideasman42@gmail.com>
Thu, 15 Sep 2011 12:26:48 +0000 (12:26 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 15 Sep 2011 12:26:48 +0000 (12:26 +0000)
also replace strcpy's which copy using "" with str[0]='\0'

25 files changed:
source/blender/blenkernel/intern/ipo.c
source/blender/blenkernel/intern/object.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/armature/poselib.c
source/blender/editors/space_outliner/outliner_edit.c
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform_generics.c
source/blender/makesrna/intern/rna_action.c
source/blender/makesrna/intern/rna_animation.c
source/blender/makesrna/intern/rna_armature.c
source/blender/makesrna/intern/rna_constraint.c
source/blender/makesrna/intern/rna_fcurve.c
source/blender/makesrna/intern/rna_key.c
source/blender/makesrna/intern/rna_mesh.c
source/blender/makesrna/intern/rna_modifier.c
source/blender/makesrna/intern/rna_nla.c
source/blender/makesrna/intern/rna_nodetree.c
source/blender/makesrna/intern/rna_object.c
source/blender/makesrna/intern/rna_pose.c
source/blender/makesrna/intern/rna_property.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_sequencer.c
source/blender/makesrna/intern/rna_text.c
source/blender/makesrna/intern/rna_texture.c
source/creator/creator.c

index 0d3f3cc5ae448a25da73282c9e580e2b0d674a30..5acd6c169a019cddc7b536d220124746df1d3390 100644 (file)
@@ -942,7 +942,7 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co
                sprintf(buf, "sequence_editor.sequences_all[\"%s\"]", seq->name+2);
        }
        else
-               strcpy(buf, ""); /* empty string */
+               buf[0]= '\0'; /* empty string */
        BLI_dynstr_append(path, buf);
        
        /* need to add dot before property if there was anything precceding this */
index c2b561b122a167dc3902efd9965ff1223bc1ff64..3644b02e7b58aa2aad3032e5237504e57d2cdbd3 100644 (file)
@@ -418,7 +418,7 @@ void unlink_object(Object *ob)
                                                for (ct= targets.first; ct; ct= ct->next) {
                                                        if (ct->tar == ob) {
                                                                ct->tar = NULL;
-                                                               strcpy(ct->subtarget, "");
+                                                               ct->subtarget[0]= '\0';
                                                                obt->recalc |= OB_RECALC_DATA;
                                                        }
                                                }
@@ -448,7 +448,7 @@ void unlink_object(Object *ob)
                                for (ct= targets.first; ct; ct= ct->next) {
                                        if (ct->tar == ob) {
                                                ct->tar = NULL;
-                                               strcpy(ct->subtarget, "");
+                                               ct->subtarget[0]= '\0';
                                                obt->recalc |= OB_RECALC_DATA;
                                        }
                                }
index 316999df6f68225f6d408a39b501318e99921b87..8364f04fefe17366c81f75aca9a2d8fc3288824c 100644 (file)
@@ -9232,7 +9232,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                                        simasel->prv_w = 96;
                                                        simasel->flag = 7; /* ??? elubie */
                                                        strcpy (simasel->dir,  U.textudir);     /* TON */
-                                                       strcpy (simasel->file, "");
+                                                       simasel->file[0]= '\0';
                                                        
                                                        simasel->returnfunc     =  NULL;
                                                        simasel->title[0]       =  0;
@@ -9462,7 +9462,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                                                
                                                                /* clear old targets to avoid problems */
                                                                data->tar = NULL;
-                                                               strcpy(data->subtarget, "");
+                                                               data->subtarget[0]= '\0';
                                                        }
                                                }
                                                else if (con->type == CONSTRAINT_TYPE_LOCLIKE) {
@@ -9492,7 +9492,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                                
                                                /* clear old targets to avoid problems */
                                                data->tar = NULL;
-                                               strcpy(data->subtarget, "");
+                                               data->subtarget[0]= '\0';
                                        }
                                }
                                else if (con->type == CONSTRAINT_TYPE_LOCLIKE) {
index 6e64d332cfd98cc7b83f1fcc084d0af6fd1a4588..67c93c4c906f68cd51bef1e4f649df339d4ef6b7 100644 (file)
@@ -1439,9 +1439,7 @@ static void poselib_preview_init_data (bContext *C, wmOperator *op)
        pld->pose->flag &= ~POSE_DO_UNLOCK;
        
        /* clear strings + search */
-       strcpy(pld->headerstr, "");
-       strcpy(pld->searchstr, "");
-       strcpy(pld->searchold, "");
+       pld->headerstr[0]= pld->searchstr[0]= pld->searchold[0]= '\0';
        pld->search_cursor= 0;
 }
 
index 05eace0d4efb53fc1051ff43d98cbf00869872bd..ada4bc6f8476f2cfa243502724855781b556c298 100644 (file)
@@ -765,7 +765,7 @@ static void outliner_find_panel(Scene *UNUSED(scene), ARegion *ar, SpaceOops *so
        }
        else {
                /* pop up panel - no previous, or user didn't want search after previous */
-               strcpy(name, "");
+               name[0]= '\0';
 // XXX         if (sbutton(name, 0, sizeof(name)-1, "Find: ") && name[0]) {
 //                     te= outliner_find_named(soops, &soops->tree, name, flags, NULL, &prevFound);
 //             }
index 82598e0b5c63cfd434438ad26a8fc0e21471686a..c8b9572730459fe6d8a3959bcef53c729ef38dbf 100644 (file)
@@ -3371,10 +3371,10 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) {
                if(chainlen)
                        sprintf(autoik, "AutoIK-Len: %d", chainlen);
                else
-                       strcpy(autoik, "");
+                       autoik[0]= '\0';
        }
        else
-               strcpy(autoik, "");
+               autoik[0]= '\0';
 
        if (t->con.mode & CON_APPLY) {
                switch(t->num.idx_max) {
index b187ca0650ccb2693eb3112a34052fca08180028..38776b51c62dfb888a5bfdf5b1c4530159700a76 100644 (file)
@@ -1666,13 +1666,13 @@ void calculatePropRatio(TransInfo *t)
                        strcpy(t->proptext, "(Random)");
                        break;
                default:
-                       strcpy(t->proptext, "");
+                       t->proptext[0]= '\0';
                }
        }
        else {
                for(i = 0 ; i < t->total; i++, td++) {
                        td->factor = 1.0;
                }
-               strcpy(t->proptext, "");
+               t->proptext[0]= '\0';
        }
 }
index 815a9c9296899bf018678597da8b427ae8714dec..53e1bf7e6f6049fc6f7e3b8077eab8219a05c51b 100644 (file)
@@ -137,7 +137,7 @@ static TimeMarker *rna_Action_pose_markers_new(bAction *act, ReportList *reports
        TimeMarker *marker = MEM_callocN(sizeof(TimeMarker), "TimeMarker");
        marker->flag= 1;
        marker->frame= 1;
-       BLI_strncpy(marker->name, name, sizeof(marker->name));
+       BLI_strncpy_utf8(marker->name, name, sizeof(marker->name));
        BLI_addtail(&act->markers, marker);
        return marker;
 }
index 0395a54be8e2d89ad0df241f1c4dd9aa6d48c8e3..2f5f22c52d58991cd459fdf9a2f9494b68594d60 100644 (file)
@@ -252,7 +252,7 @@ static void rna_ksPath_RnaPath_get(PointerRNA *ptr, char *value)
        if (ksp->rna_path)
                strcpy(value, ksp->rna_path);
        else
-               strcpy(value, "");
+               value[0]= '\0';
 }
 
 static int rna_ksPath_RnaPath_length(PointerRNA *ptr)
index e2399b5b57cf4cf7b011ec7458671d82bfe296e3..4ed5d2a125a1f782bb44adad789161448fb77763 100644 (file)
@@ -253,7 +253,7 @@ static void rna_EditBone_name_set(PointerRNA *ptr, const char *value)
        char oldname[sizeof(ebone->name)], newname[sizeof(ebone->name)];
        
        /* need to be on the stack */
-       BLI_strncpy(newname, value, sizeof(ebone->name));
+       BLI_strncpy_utf8(newname, value, sizeof(ebone->name));
        BLI_strncpy(oldname, ebone->name, sizeof(ebone->name));
        
        ED_armature_bone_rename(arm, oldname, newname);
@@ -266,7 +266,7 @@ static void rna_Bone_name_set(PointerRNA *ptr, const char *value)
        char oldname[sizeof(bone->name)], newname[sizeof(bone->name)];
        
        /* need to be on the stack */
-       BLI_strncpy(newname, value, sizeof(bone->name));
+       BLI_strncpy_utf8(newname, value, sizeof(bone->name));
        BLI_strncpy(oldname, bone->name, sizeof(bone->name));
 
        ED_armature_bone_rename(arm, oldname, newname);
index 22d9a19f93360a4ebf0f3e7355a191d03ce42a39..fdbb4f09f9333310b11addfa61fe585bdf460dbc 100644 (file)
@@ -170,7 +170,7 @@ static void rna_Constraint_name_set(PointerRNA *ptr, const char *value)
        BLI_strncpy(oldname, con->name, sizeof(con->name));
        
        /* copy the new name into the name slot */
-       BLI_strncpy(con->name, value, sizeof(con->name));
+       BLI_strncpy_utf8(con->name, value, sizeof(con->name));
        
        /* make sure name is unique */
        if (ptr->id.data) {
index e922a007249a46c6ea91dc94add1fadea5a0a162..c0c8ac6b88a010eb913e49ecce4ad821eb2b9400 100644 (file)
@@ -215,7 +215,7 @@ static void rna_DriverTarget_RnaPath_get(PointerRNA *ptr, char *value)
        if (dtar->rna_path)
                strcpy(value, dtar->rna_path);
        else
-               strcpy(value, "");
+               value[0]= '\0';
 }
 
 static int rna_DriverTarget_RnaPath_length(PointerRNA *ptr)
@@ -309,7 +309,7 @@ static void rna_FCurve_RnaPath_get(PointerRNA *ptr, char *value)
        if (fcu->rna_path)
                strcpy(value, fcu->rna_path);
        else
-               strcpy(value, "");
+               value[0]= '\0';
 }
 
 static int rna_FCurve_RnaPath_length(PointerRNA *ptr)
index 3e65eb8665ed6d2f59e6a526763dc15be78ad3e2..ad6f67cddaf6414c18d5f68adbba9ecf0d1b9ed7 100644 (file)
@@ -76,7 +76,7 @@ void rna_ShapeKey_name_set(PointerRNA *ptr, const char *value)
        BLI_strncpy(oldname, kb->name, sizeof(kb->name));
        
        /* copy the new name into the name slot */
-       BLI_strncpy(kb->name, value, sizeof(kb->name));
+       BLI_strncpy_utf8(kb->name, value, sizeof(kb->name));
        
        /* make sure the name is truly unique */
        if (ptr->id.data) {
index 80c98e8c428b5f9d83cacd925b923701d7861ddb..b0554ea5b4f89f2828f84c44cb342ebbc78b3fc7 100644 (file)
@@ -690,7 +690,7 @@ static void rna_MeshTextureFaceLayer_name_set(PointerRNA *ptr, const char *value
        Mesh *me= (Mesh*)ptr->id.data;
        CustomData *fdata= rna_mesh_fdata(me);
        CustomDataLayer *cdl= (CustomDataLayer*)ptr->data;
-       BLI_strncpy(cdl->name, value, sizeof(cdl->name));
+       BLI_strncpy_utf8(cdl->name, value, sizeof(cdl->name));
        CustomData_set_layer_unique_name(fdata, cdl - fdata->layers);
 }
 
@@ -802,7 +802,7 @@ static void rna_MeshColorLayer_name_set(PointerRNA *ptr, const char *value)
        Mesh *me= (Mesh*)ptr->id.data;
        CustomData *fdata= rna_mesh_fdata(me);
        CustomDataLayer *cdl= (CustomDataLayer*)ptr->data;
-       BLI_strncpy(cdl->name, value, sizeof(cdl->name));
+       BLI_strncpy_utf8(cdl->name, value, sizeof(cdl->name));
        CustomData_set_layer_unique_name(fdata, cdl - fdata->layers);
 }
 
index 464f676b7f6d5831c656c25a6ef23cdd5b43d170..b83f06c633c0c21cc33f2fe1c2a62b3b2927afe7 100644 (file)
@@ -211,7 +211,7 @@ void rna_Modifier_name_set(PointerRNA *ptr, const char *value)
        BLI_strncpy(oldname, md->name, sizeof(md->name));
        
        /* copy the new name into the name slot */
-       BLI_strncpy(md->name, value, sizeof(md->name));
+       BLI_strncpy_utf8(md->name, value, sizeof(md->name));
        
        /* make sure the name is truly unique */
        if (ptr->id.data) {
index ef4adde6fb4379c61a6adb6d801dbd0a3ffc0e33..2a234dfaa619c6d83d983b8719f350720dd03d38 100644 (file)
@@ -59,7 +59,7 @@ static void rna_NlaStrip_name_set(PointerRNA *ptr, const char *value)
        NlaStrip *data= (NlaStrip *)ptr->data;
        
        /* copy the name first */
-       BLI_strncpy(data->name, value, sizeof(data->name));
+       BLI_strncpy_utf8(data->name, value, sizeof(data->name));
        
        /* validate if there's enough info to do so */
        if (ptr->id.data) {
index 0554e4d00adef503650844811ae19d6572810916..61947977feecec446af39f56891440fbb9414e7b 100644 (file)
@@ -361,7 +361,7 @@ static void rna_Node_name_set(PointerRNA *ptr, const char *value)
        /* make a copy of the old name first */
        BLI_strncpy(oldname, node->name, sizeof(node->name));
        /* set new name */
-       BLI_strncpy(node->name, value, sizeof(node->name));
+       BLI_strncpy_utf8(node->name, value, sizeof(node->name));
        
        nodeUniqueName(ntree, node);
        
index bb223ac95b41540330ba12ddf25d7fa76c3ceb84..e7b5529af02a4cb51ff27df831e8cf6d373995de 100644 (file)
@@ -466,7 +466,7 @@ void rna_VertexGroup_name_set(PointerRNA *ptr, const char *value)
 {
        Object *ob= (Object *)ptr->id.data;
        bDeformGroup *dg= (bDeformGroup *)ptr->data;
-       BLI_strncpy(dg->name, value, sizeof(dg->name));
+       BLI_strncpy_utf8(dg->name, value, sizeof(dg->name));
        defgroup_unique_name(dg, ob);
 }
 
@@ -512,7 +512,7 @@ void rna_object_vgroup_name_index_get(PointerRNA *ptr, char *value, int index)
        dg= BLI_findlink(&ob->defbase, index-1);
 
        if(dg) BLI_strncpy(value, dg->name, sizeof(dg->name));
-       else BLI_strncpy(value, "", sizeof(dg->name));
+       else value[0]= '\0';
 }
 
 int rna_object_vgroup_name_index_length(PointerRNA *ptr, int index)
@@ -535,7 +535,7 @@ void rna_object_vgroup_name_set(PointerRNA *ptr, const char *value, char *result
        Object *ob= (Object*)ptr->id.data;
        bDeformGroup *dg= defgroup_find_name(ob, value);
        if(dg) {
-               BLI_strncpy(result, value, maxlen);
+               BLI_strncpy(result, value, maxlen); /* no need for BLI_strncpy_utf8, since this matches an existing group */
                return;
        }
 
@@ -562,7 +562,7 @@ void rna_object_uvlayer_name_set(PointerRNA *ptr, const char *value, char *resul
                }
        }
 
-       BLI_strncpy(result, "", maxlen);
+       result[0]= '\0';
 }
 
 void rna_object_vcollayer_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen)
@@ -585,7 +585,7 @@ void rna_object_vcollayer_name_set(PointerRNA *ptr, const char *value, char *res
                }
        }
 
-       BLI_strncpy(result, "", maxlen);
+       result[0]= '\0';
 }
 
 static int rna_Object_active_material_index_get(PointerRNA *ptr)
@@ -836,7 +836,7 @@ static void rna_MaterialSlot_name_get(PointerRNA *ptr, char *str)
        if(ma)
                strcpy(str, ma->id.name+2);
        else
-               strcpy(str, "");
+               str[0]= '\0';
 }
 
 static void rna_MaterialSlot_update(Main *bmain, Scene *scene, PointerRNA *ptr)
index 0dd8218d1b92384f021fb367d1778324ca4866f9..434634f6b10e813fdf1024226900b99bb0ffe66e 100644 (file)
@@ -222,7 +222,7 @@ static void rna_PoseChannel_name_set(PointerRNA *ptr, const char *value)
        char oldname[sizeof(pchan->name)], newname[sizeof(pchan->name)];
 
        /* need to be on the stack */
-       BLI_strncpy(newname, value, sizeof(pchan->name));
+       BLI_strncpy_utf8(newname, value, sizeof(pchan->name));
        BLI_strncpy(oldname, pchan->name, sizeof(pchan->name));
 
        ED_armature_bone_rename(ob->data, oldname, newname);
@@ -411,7 +411,7 @@ static void rna_pose_bgroup_name_index_get(PointerRNA *ptr, char *value, int ind
        grp= BLI_findlink(&pose->agroups, index-1);
 
        if(grp) BLI_strncpy(value, grp->name, sizeof(grp->name));
-       else BLI_strncpy(value, "", sizeof(grp->name)); // XXX if invalid pointer, won't this crash?
+       else value[0]= '\0';
 }
 
 static int rna_pose_bgroup_name_index_length(PointerRNA *ptr, int index)
@@ -451,7 +451,7 @@ static void rna_pose_pgroup_name_set(PointerRNA *ptr, const char *value, char *r
                }
        }
        
-       BLI_strncpy(result, "", maxlen);
+       result[0]= '\0';
 }
 #endif
 
index 9fd5610a577081020ec0c1730f947d1346e3432e..e2b886b8d38c5bc98578f933181b1f41b954948f 100644 (file)
@@ -88,7 +88,7 @@ static void rna_GameProperty_type_set(PointerRNA *ptr, int value)
 static void rna_GameProperty_name_set(PointerRNA *ptr, const char *value)
 {
        bProperty *prop= (bProperty*)(ptr->data);
-       BLI_strncpy(prop->name, value, sizeof(prop->name));
+       BLI_strncpy_utf8(prop->name, value, sizeof(prop->name));
        unique_property(NULL, prop, 1);
 }
 
index 197ddd2ba06bab4c30492e23010a1632e265d09f..2377c88113a310be62a33f183511be5ef953eabf 100644 (file)
@@ -737,7 +737,7 @@ static void rna_RenderSettings_engine_set(PointerRNA *ptr, int value)
        RenderEngineType *type= BLI_findlink(&R_engines, value);
 
        if(type)
-               BLI_strncpy(rd->engine, type->idname, sizeof(rd->engine));
+               BLI_strncpy_utf8(rd->engine, type->idname, sizeof(rd->engine));
 }
 
 static EnumPropertyItem *rna_RenderSettings_engine_itemf(bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
@@ -810,7 +810,7 @@ static void rna_SceneRenderLayer_name_set(PointerRNA *ptr, const char *value)
        Scene *scene= (Scene*)ptr->id.data;
        SceneRenderLayer *rl= (SceneRenderLayer*)ptr->data;
 
-       BLI_strncpy(rl->name, value, sizeof(rl->name));
+       BLI_strncpy_utf8(rl->name, value, sizeof(rl->name));
 
        if(scene->nodetree) {
                bNode *node;
@@ -1011,7 +1011,7 @@ static TimeMarker *rna_TimeLine_add(Scene *scene, const char name[])
        TimeMarker *marker = MEM_callocN(sizeof(TimeMarker), "TimeMarker");
        marker->flag= SELECT;
        marker->frame= 1;
-       BLI_strncpy(marker->name, name, sizeof(marker->name));
+       BLI_strncpy_utf8(marker->name, name, sizeof(marker->name));
        BLI_addtail(&scene->markers, marker);
        return marker;
 }
index 627c227496524c1e21a056584f56108dd683bff4..79724adf91c72a7577f9e5ee5c9088baea574cb3 100644 (file)
@@ -359,7 +359,7 @@ static void rna_Sequence_name_set(PointerRNA *ptr, const char *value)
        BLI_strncpy(oldname, seq->name+2, sizeof(seq->name)-2);
        
        /* copy the new name into the name slot */
-       BLI_strncpy(seq->name+2, value, sizeof(seq->name)-2);
+       BLI_strncpy_utf8(seq->name+2, value, sizeof(seq->name)-2);
        
        /* make sure the name is unique */
        seqbase_unique_name_recursive(&scene->ed->seqbase, seq);
index 959f9db851bc5426a11248d16b3da991b1de63a0..6a1e93fce41eb19e1a26f2efdffc6ba336d88342 100644 (file)
@@ -53,7 +53,7 @@ static void rna_Text_filename_get(PointerRNA *ptr, char *value)
        if(text->name)
                strcpy(value, text->name);
        else
-               strcpy(value, "");
+               value[0]= '\0';
 }
 
 static int rna_Text_filename_length(PointerRNA *ptr)
@@ -88,7 +88,7 @@ static void rna_TextLine_body_get(PointerRNA *ptr, char *value)
        if(line->line)
                strcpy(value, line->line);
        else
-               strcpy(value, "");
+               value[0]= '\0';
 }
 
 static int rna_TextLine_body_length(PointerRNA *ptr)
index 890be76c49abe0d7d1ac61313b8d5118821a259b..608a7326d79eaf1b56a06d57fef5ce8bbb55b10f 100644 (file)
@@ -260,7 +260,7 @@ static void rna_TextureSlot_name_get(PointerRNA *ptr, char *str)
        if(mtex->tex)
                strcpy(str, mtex->tex->id.name+2);
        else
-               strcpy(str, "");
+               str[0]= '\0';
 }
 
 static int rna_TextureSlot_output_node_get(PointerRNA *ptr)
index 264b4fc6208c54bdc3a401b51fc6db6e2d875494..91c2d74dc26cfd4092817ef2aff722600c297502 100644 (file)
@@ -560,7 +560,7 @@ static int set_engine(int argc, const char **argv, void *data)
                                RenderData *rd = &scene->r;
 
                                if(BLI_findstring(&R_engines, argv[1], offsetof(RenderEngineType, idname))) {
-                                       BLI_strncpy(rd->engine, argv[1], sizeof(rd->engine));
+                                       BLI_strncpy_utf8(rd->engine, argv[1], sizeof(rd->engine));
                                }
                        }
                }