strcpy() --> BLI_strncpy(), where source strings are not fixed and target size is...
authorCampbell Barton <ideasman42@gmail.com>
Wed, 19 Oct 2011 23:10:54 +0000 (23:10 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 19 Oct 2011 23:10:54 +0000 (23:10 +0000)
39 files changed:
source/blender/blenkernel/BKE_packedFile.h
source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/modifier.c
source/blender/blenkernel/intern/node.c
source/blender/blenkernel/intern/packedFile.c
source/blender/blenkernel/intern/pointcache.c
source/blender/blenkernel/intern/property.c
source/blender/blenkernel/intern/sequencer.c
source/blender/blenkernel/intern/sound.c
source/blender/blenkernel/intern/texture.c
source/blender/blenlib/intern/fileops.c
source/blender/blenlib/intern/freetypefont.c
source/blender/blenlib/intern/storage.c
source/blender/blenloader/BLO_readfile.h
source/blender/blenloader/BLO_runtime.h
source/blender/blenloader/intern/readblenentry.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/runtime.c
source/blender/collada/AnimationImporter.cpp
source/blender/editors/armature/editarmature.c
source/blender/editors/armature/poselib.c
source/blender/editors/gpencil/editaction_gpencil.c
source/blender/editors/interface/resources.c
source/blender/editors/object/object_constraint.c
source/blender/editors/object/object_relations.c
source/blender/editors/object/object_vgroup.c
source/blender/editors/render/render_preview.c
source/blender/editors/screen/screendump.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/sculpt_undo.c
source/blender/editors/space_sequencer/sequencer_add.c
source/blender/editors/space_sequencer/sequencer_edit.c
source/blender/imbuf/intern/anim_movie.c
source/blender/makesrna/intern/rna_lattice.c
source/blender/makesrna/intern/rna_object_force.c
source/blender/modifiers/intern/MOD_solidify.c
source/blender/nodes/intern/node_common.c
source/blender/render/intern/source/renderdatabase.c
source/gameengine/GamePlayer/ghost/GPG_ghost.cpp

index 556ff26e62102063cb5116de4099cc49f6724bb1..f1c7356e6b0b11a6f5ce1ffbd9910df43d1fac20 100644 (file)
@@ -51,7 +51,7 @@ struct PackedFile *newPackedFileMemory(void *mem, int memlen);
 void packAll(struct Main *bmain, struct ReportList *reports);
 
 /* unpack */
-char *unpackFile(struct ReportList *reports, char *abs_name, char *local_name, struct PackedFile *pf, int how);
+char *unpackFile(struct ReportList *reports, const char *abs_name, const char *local_name, struct PackedFile *pf, int how);
 int unpackVFont(struct ReportList *reports, struct VFont *vfont, int how);
 int unpackSound(struct Main *bmain, struct ReportList *reports, struct bSound *sound, int how);
 int unpackImage(struct ReportList *reports, struct Image *ima, int how);
index 1de581034a44a4cf57f4d911961bce773096b9f6..37982e7fec93afcd08cb85addfc21373464fecc5 100644 (file)
@@ -906,8 +906,8 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d
        
        if (scene->r.stamp & R_STAMP_MARKER) {
                char *name = scene_find_last_marker_name(scene, CFRA);
-       
-               if (name)       strcpy(text, name);
+
+               if (name)       BLI_strncpy(text, name, sizeof(text));
                else            strcpy(text, "<none>");
 
                BLI_snprintf(stamp_data->marker, sizeof(stamp_data->marker), do_prefix ? "Marker %s":"%s", text);
@@ -980,7 +980,7 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d
        if (scene->r.stamp & R_STAMP_SEQSTRIP) {
                Sequence *seq= seq_foreground_frame_get(scene, scene->r.cfra);
        
-               if (seq) strcpy(text, seq->name+2);
+               if (seq)        BLI_strncpy(text, seq->name+2, sizeof(text));
                else            strcpy(text, "<none>");
 
                BLI_snprintf(stamp_data->strip, sizeof(stamp_data->strip), do_prefix ? "Strip %s":"%s", text);
index 9de75a499984478ddbd72c1a70092021d8fd47be..2cee9676e5e78cd2281d122700c091a2ed6f36da 100644 (file)
@@ -86,8 +86,8 @@ ModifierData *modifier_new(int type)
        ModifierTypeInfo *mti = modifierType_getInfo(type);
        ModifierData *md = MEM_callocN(mti->structSize, mti->structName);
        
-       // FIXME: we need to make the name always be unique somehow...
-       strcpy(md->name, mti->name);
+       /* note, this name must be made unique later */
+       BLI_strncpy(md->name, mti->name, sizeof(md->name));
 
        md->type = type;
        md->mode = eModifierMode_Realtime
index a46b358798abd9e257a11eafdcd2122af1c376a3..cb1f52a626525f859cf8ab76bc252a989a5a4a36 100644 (file)
@@ -374,7 +374,7 @@ void nodeMakeDynamicType(bNode *node)
                /*node->typeinfo= MEM_dupallocN(ntype);*/
                bNodeType *newtype= MEM_callocN(sizeof(bNodeType), "dynamic bNodeType");
                *newtype= *ntype;
-               strcpy(newtype->name, ntype->name);
+               BLI_strncpy(newtype->name, ntype->name, sizeof(newtype->name));
                node->typeinfo= newtype;
        }
 }
index 2c8975e9cb4252798abc2047bb7d9321b2840b56..0041cd33c145e0afd3602542b4fd40d71815e8e6 100644 (file)
@@ -182,7 +182,7 @@ PackedFile *newPackedFile(ReportList *reports, const char *filename, const char
        
        // convert relative filenames to absolute filenames
        
-       strcpy(name, filename);
+       BLI_strncpy(name, filename, sizeof(name));
        BLI_path_abs(name, basepath);
        
        // open the file
@@ -240,7 +240,7 @@ void packAll(Main *bmain, ReportList *reports)
 }
 
 
-/*
+#if 0
 
 // attempt to create a function that generates an unique filename
 // this will work when all funtions in fileops.c understand relative filenames...
@@ -249,6 +249,7 @@ static char *find_new_name(char *name)
 {
        char tempname[FILE_MAXDIR + FILE_MAXFILE];
        char *newname;
+       size_t len;
        
        if (fop_exists(name)) {
                for (number = 1; number <= 999; number++) {
@@ -258,14 +259,12 @@ static char *find_new_name(char *name)
                        }
                }
        }
-       
-       newname = mallocN(strlen(tempname) + 1, "find_new_name");
-       strcpy(newname, tempname);
-       
-       return(newname);
+       len= strlen(tempname) + 1;
+       newname = MEM_mallocN(len, "find_new_name");
+       memcpy(newname, tempname, len * sizeof(char));
+       return newname;
 }
-       
-*/
+#endif
 
 int writePackedFile(ReportList *reports, const char *filename, PackedFile *pf, int guimode)
 {
@@ -277,12 +276,12 @@ int writePackedFile(ReportList *reports, const char *filename, PackedFile *pf, i
        
        if (guimode) {} //XXX  waitcursor(1);
        
-       strcpy(name, filename);
+       BLI_strncpy(name, filename, sizeof(name));
        BLI_path_abs(name, G.main->name);
        
        if (BLI_exists(name)) {
                for (number = 1; number <= 999; number++) {
-                       sprintf(tempname, "%s.%03d_", name, number);
+                       BLI_snprintf(tempname, sizeof(tempname), "%s.%03d_", name, number);
                        if (! BLI_exists(tempname)) {
                                if (BLI_copy_fileops(name, tempname) == RET_OK) {
                                        remove_tmp = TRUE;
@@ -342,7 +341,7 @@ int checkPackedFile(const char *filename, PackedFile *pf)
        char buf[4096];
        char name[FILE_MAXDIR + FILE_MAXFILE];
        
-       strcpy(name, filename);
+       BLI_strncpy(name, filename, sizeof(name));
        BLI_path_abs(name, G.main->name);
        
        if (stat(name, &st)) {
@@ -392,9 +391,10 @@ there was an error or when the user desides to cancel the operation.
 
 */
 
-char *unpackFile(ReportList *reports, char *abs_name, char *local_name, PackedFile *pf, int how)
+char *unpackFile(ReportList *reports, const char *abs_name, const char *local_name, PackedFile *pf, int how)
 {
-       char *newname = NULL, *temp = NULL;
+       char *newname = NULL;
+       const char *temp = NULL;
        
        // char newabs[FILE_MAXDIR + FILE_MAXFILE];
        // char newlocal[FILE_MAXDIR + FILE_MAXFILE];
@@ -437,12 +437,11 @@ char *unpackFile(ReportList *reports, char *abs_name, char *local_name, PackedFi
                }
                
                if (temp) {
-                       newname = MEM_mallocN(strlen(temp) + 1, "unpack_file newname");
-                       strcpy(newname, temp);
+                       newname= BLI_strdup(temp);
                }
        }
        
-       return (newname);
+       return newname;
 }
 
 
@@ -453,17 +452,17 @@ int unpackVFont(ReportList *reports, VFont *vfont, int how)
        int ret_value = RET_ERROR;
        
        if (vfont != NULL) {
-               strcpy(localname, vfont->name);
+               BLI_strncpy(localname, vfont->name, sizeof(localname));
                BLI_splitdirstring(localname, fi);
                
-               sprintf(localname, "//fonts/%s", fi);
+               BLI_snprintf(localname, sizeof(localname), "//fonts/%s", fi);
                
                newname = unpackFile(reports, vfont->name, localname, vfont->packedfile, how);
                if (newname != NULL) {
                        ret_value = RET_OK;
                        freePackedFile(vfont->packedfile);
                        vfont->packedfile = NULL;
-                       strcpy(vfont->name, newname);
+                       BLI_strncpy(vfont->name, newname, sizeof(vfont->name));
                        MEM_freeN(newname);
                }
        }
@@ -478,13 +477,13 @@ int unpackSound(Main *bmain, ReportList *reports, bSound *sound, int how)
        int ret_value = RET_ERROR;
 
        if (sound != NULL) {
-               strcpy(localname, sound->name);
+               BLI_strncpy(localname, sound->name, sizeof(localname));
                BLI_splitdirstring(localname, fi);
-               sprintf(localname, "//sounds/%s", fi);
+               BLI_snprintf(localname, sizeof(localname), "//sounds/%s", fi);
 
                newname = unpackFile(reports, sound->name, localname, sound->packedfile, how);
                if (newname != NULL) {
-                       strcpy(sound->name, newname);
+                       BLI_strncpy(sound->name, newname, sizeof(sound->name));
                        MEM_freeN(newname);
 
                        freePackedFile(sound->packedfile);
@@ -506,16 +505,16 @@ int unpackImage(ReportList *reports, Image *ima, int how)
        int ret_value = RET_ERROR;
        
        if (ima != NULL) {
-               strcpy(localname, ima->name);
+               BLI_strncpy(localname, ima->name, sizeof(localname));
                BLI_splitdirstring(localname, fi);
-               sprintf(localname, "//textures/%s", fi);
-                       
+               BLI_snprintf(localname, sizeof(localname), "//textures/%s", fi);
+
                newname = unpackFile(reports, ima->name, localname, ima->packedfile, how);
                if (newname != NULL) {
                        ret_value = RET_OK;
                        freePackedFile(ima->packedfile);
                        ima->packedfile = NULL;
-                       strcpy(ima->name, newname);
+                       BLI_strncpy(ima->name, newname, sizeof(ima->name));
                        MEM_freeN(newname);
                        BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
                }
index bc5bc87b1fac43a978144306cb412f82072be45d..8e5452e27041f43fcf9d20aefe0e93214c3818f8 100644 (file)
@@ -2891,24 +2891,24 @@ void BKE_ptcache_disk_cache_rename(PTCacheID *pid, char *from, char *to)
        char ext[MAX_PTCACHE_PATH];
 
        /* save old name */
-       strcpy(old_name, pid->cache->name);
+       BLI_strncpy(old_name, pid->cache->name, sizeof(old_name));
 
        /* get "from" filename */
-       strcpy(pid->cache->name, from);
+       BLI_strncpy(pid->cache->name, from, sizeof(pid->cache->name));
 
        len = ptcache_filename(pid, old_filename, 0, 0, 0); /* no path */
 
        ptcache_path(pid, path);
        dir = opendir(path);
        if(dir==NULL) {
-               strcpy(pid->cache->name, old_name);
+               BLI_strncpy(pid->cache->name, old_name, sizeof(pid->cache->name));
                return;
        }
 
        BLI_snprintf(ext, sizeof(ext), "_%02u"PTCACHE_EXT, pid->stack_index);
 
        /* put new name into cache */
-       strcpy(pid->cache->name, to);
+       BLI_strncpy(pid->cache->name, to, sizeof(pid->cache->name));
 
        while ((de = readdir(dir)) != NULL) {
                if (strstr(de->d_name, ext)) { /* do we have the right extension?*/
@@ -2963,7 +2963,7 @@ void BKE_ptcache_load_external(PTCacheID *pid)
        if(cache->index >= 0)
                BLI_snprintf(ext, sizeof(ext), "_%02d"PTCACHE_EXT, cache->index);
        else
-               strcpy(ext, PTCACHE_EXT);
+               BLI_strncpy(ext, PTCACHE_EXT, sizeof(ext));
        
        while ((de = readdir(dir)) != NULL) {
                if (strstr(de->d_name, ext)) { /* do we have the right extension?*/
index cdf2e39a4dd973d78f5356b34ce92c6bc0b7d183..e0e2876f79e11877f3205a98ea7168efaec03c12 100644 (file)
@@ -166,7 +166,7 @@ void unique_property(bProperty *first, bProperty *prop, int force)
                        int i= 0;
 
                        /* strip numbers */
-                       strcpy(base_name, prop->name);
+                       BLI_strncpy(base_name, prop->name, sizeof(base_name));
                        for(i= strlen(base_name)-1; (i>=0 && isdigit(base_name[i])); i--) {
                                base_name[i]= '\0';
                        }
@@ -178,7 +178,7 @@ void unique_property(bProperty *first, bProperty *prop, int force)
                                strcat(new_name, num);
                        } while(get_property__internal(first, prop, new_name));
 
-                       strcpy(prop->name, new_name);
+                       BLI_strncpy(prop->name, new_name, sizeof(prop->name));
                }
        }
 }
@@ -257,7 +257,7 @@ void set_property(bProperty *prop, char *str)
                *((float *)&prop->data)= (float)atof(str);
                break;
        case GPROP_STRING:
-               strcpy(prop->poin, str);
+               strcpy(prop->poin, str); /* TODO - check size? */
                break;
        }
        
index 00534400cf135e28572c1680975aaa8e48b755f7..a7c1913092916846671563969ea4c5d255930ff4 100644 (file)
@@ -866,8 +866,8 @@ void seqbase_unique_name_recursive(ListBase *seqbasep, struct Sequence *seq)
        SeqUniqueInfo sui;
        char *dot;
        sui.seq= seq;
-       strcpy(sui.name_src, seq->name+2);
-       strcpy(sui.name_dest, seq->name+2);
+       BLI_strncpy(sui.name_src, seq->name+2, sizeof(sui.name_src));
+       BLI_strncpy(sui.name_dest, seq->name+2, sizeof(sui.name_dest));
 
        sui.count= 1;
        sui.match= 1; /* assume the worst to start the loop */
@@ -887,7 +887,7 @@ void seqbase_unique_name_recursive(ListBase *seqbasep, struct Sequence *seq)
                seqbase_recursive_apply(seqbasep, seqbase_unique_name_recursive_cb, &sui);
        }
 
-       strcpy(seq->name+2, sui.name_dest);
+       BLI_strncpy(seq->name+2, sui.name_dest, sizeof(seq->name)-2);
 }
 
 static const char *give_seqname_by_type(int type)
@@ -1204,7 +1204,7 @@ static int seq_proxy_get_fname(SeqRenderData context, Sequence * seq, int cfra,
           sorry folks, please rebuild your proxies... */
 
        if (seq->flag & (SEQ_USE_PROXY_CUSTOM_DIR|SEQ_USE_PROXY_CUSTOM_FILE)) {
-               strcpy(dir, seq->strip->proxy->dir);
+               BLI_strncpy(dir, seq->strip->proxy->dir, sizeof(dir));
        } else if (seq->type == SEQ_IMAGE) {
                BLI_snprintf(dir, PROXY_MAXFILE, "%s/BL_proxy", seq->strip->dir);
        } else {
@@ -3360,9 +3360,9 @@ int seq_swap(Sequence *seq_a, Sequence *seq_b, const char **error_str)
        SWAP(Sequence, *seq_a, *seq_b);
 
        /* swap back names so animation fcurves dont get swapped */
-       strcpy(name, seq_a->name+2);
-       strcpy(seq_a->name+2, seq_b->name+2);
-       strcpy(seq_b->name+2, name);
+       BLI_strncpy(name, seq_a->name+2, sizeof(name));
+       BLI_strncpy(seq_a->name+2, seq_b->name+2, sizeof(seq_b->name)-2);
+       BLI_strncpy(seq_b->name+2, name, sizeof(seq_b->name)-2);
 
        /* swap back opacity, and overlay mode */
        SWAP(int, seq_a->blend_mode, seq_b->blend_mode);
index 07df12d546890bfc766721c8bc98df7472fd3b22..02e381fe9b430691f9055ded56eb88feb0d85aff 100644 (file)
@@ -79,9 +79,9 @@ struct bSound* sound_new_file(struct Main *bmain, const char *filename)
        char str[FILE_MAX];
        char *path;
 
-       int len;
+       size_t len;
 
-       strcpy(str, filename);
+       BLI_strncpy(str, filename, sizeof(str));
 
        path = /*bmain ? bmain->name :*/ G.main->name;
 
index d344f79bb6caed1b34d6ac41f715266bd33d3518..7d720aed62caf6b9715aaa836c59391e47178dcf 100644 (file)
@@ -992,7 +992,7 @@ void autotexname(Tex *tex)
                if(tex->type==TEX_IMAGE) {
                        ima= tex->ima;
                        if(ima) {
-                               strcpy(di, ima->name);
+                               BLI_strncpy(di, ima->name, sizeof(di));
                                BLI_splitdirstring(di, fi);
                                strcpy(di, "I.");
                                strcat(di, fi);
index 9ccd7fbe12164ebb7adff730fd7fffd4009e4c6e..e848ad8d0d38ccba5af0b2b8ee5d60fed13c2660 100644 (file)
@@ -227,7 +227,7 @@ int BLI_move(const char *file, const char *to) {
        // it has to be 'mv filename filename' and not
        // 'mv filename destdir'
 
-       strcpy(str, to);
+       BLI_strncpy(str, to, sizeof(str));
        // points 'to' to a directory ?
        if (BLI_last_slash(str) == (str + strlen(str) - 1)) {
                if (BLI_last_slash(file) != NULL) {
@@ -252,7 +252,7 @@ int BLI_copy_fileops(const char *file, const char *to) {
        // it has to be 'cp filename filename' and not
        // 'cp filename destdir'
 
-       strcpy(str, to);
+       BLI_strncpy(str, to, sizeof(str));
        // points 'to' to a directory ?
        if (BLI_last_slash(str) == (str + strlen(str) - 1)) {
                if (BLI_last_slash(file) != NULL) {
@@ -286,7 +286,7 @@ void BLI_recurdir_fileops(const char *dirname) {
        // blah1/blah2/ (with slash) after creating
        // blah1/blah2 (without slash)
 
-       strcpy(tmp, dirname);
+       BLI_strncpy(tmp, dirname, sizeof(tmp));
        lslash= BLI_last_slash(tmp);
 
        if (lslash == tmp + strlen(tmp) - 1) {
@@ -371,7 +371,7 @@ void BLI_recurdir_fileops(const char *dirname) {
                
        if (BLI_exists(dirname)) return;
 
-       strcpy(tmp, dirname);
+       BLI_strncpy(tmp, dirname, sizeof(tmp));
                
        lslash= BLI_last_slash(tmp);
        if (lslash) {
index 0fe028eb3c0df8b2bb1241ddc3aa557fbb818dbe..7e5d03423e5fb86dda643cb3127ad38d480d1217 100644 (file)
@@ -364,7 +364,7 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf)
 
        // get the name
        fontname = FT_Get_Postscript_Name(face);
-       strcpy(vfd->name, (fontname == NULL) ? "" : fontname);
+       BLI_strncpy(vfd->name, (fontname == NULL) ? "" : fontname, sizeof(vfd->name));
 
        // Extract the first 256 character from TTF
        lcode= charcode= FT_Get_First_Char(face, &glyph_index);
index e336b914ffa090e229ccd68c7f24d24ff75fecd2..7638e95b4ec2d6b8e4f6070ec109d9e674affd6d 100644 (file)
@@ -304,15 +304,15 @@ void BLI_adddirstrings(void)
        for(num=0, file= files; num<actnum; num++, file++){
 #ifdef WIN32
                mode = 0;
-               strcpy(file->mode1, types[0]);
-               strcpy(file->mode2, types[0]);
-               strcpy(file->mode3, types[0]);
+               BLI_strncpy(file->mode1, types[0], sizeof(file->mode1));
+               BLI_strncpy(file->mode2, types[0], sizeof(file->mode2));
+               BLI_strncpy(file->mode3, types[0], sizeof(file->mode3));
 #else
                mode = file->s.st_mode;
 
-               strcpy(file->mode1, types[(mode & 0700) >> 6]);
-               strcpy(file->mode2, types[(mode & 0070) >> 3]);
-               strcpy(file->mode3, types[(mode & 0007)]);
+               BLI_strncpy(file->mode1, types[(mode & 0700) >> 6], sizeof(file->mode1));
+               BLI_strncpy(file->mode2, types[(mode & 0070) >> 3], sizeof(file->mode2));
+               BLI_strncpy(file->mode3, types[(mode & 0007)], sizeof(file->mode3));
                
                if (((mode & S_ISGID) == S_ISGID) && (file->mode2[2]=='-'))file->mode2[2]='l';
 
index e7be98d955d5daacc8dca9fe2b76a4dd0dfdc43a..2799b2165f0e3d06f866acd3c41c38bbf900959d 100644 (file)
@@ -252,7 +252,7 @@ void BLO_library_append_end(const struct bContext *C, struct Main *mainl, BlendH
 
 void *BLO_library_read_struct(struct FileData *fd, struct BHead *bh, const char *blockname);
 
-BlendFileData* blo_read_blendafterruntime(int file, char *name, int actualsize, struct ReportList *reports);
+BlendFileData* blo_read_blendafterruntime(int file, const char *name, int actualsize, struct ReportList *reports);
 
 #ifdef __cplusplus
 } 
index 920b14e92fa70bab393d64320dcab5544221290f..0a3ceeefa78c1d2eb1df856b13220137627edb3e 100644 (file)
@@ -42,8 +42,8 @@ extern "C" {
 struct BlendFileData;
 struct ReportList;
 
-int BLO_is_a_runtime(char *file);
-struct BlendFileData *BLO_read_runtime(char *file, struct ReportList *reports);
+int BLO_is_a_runtime(const char *file);
+struct BlendFileData *BLO_read_runtime(const char *file, struct ReportList *reports);
 
 #ifdef __cplusplus
 }
index 0e93e5fa8c09b9caf196fde8f12526afadfd158b..220784c9ff70d6c2827435184a9b4a91f347e539 100644 (file)
@@ -288,7 +288,7 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain, const char *filename, MemFil
        fd = blo_openblendermemfile(memfile, reports);
        if (fd) {
                fd->reports= reports;
-               strcpy(fd->relabase, filename);
+               BLI_strncpy(fd->relabase, filename, sizeof(fd->relabase));
                
                /* clear ob->proxy_from pointers in old main */
                blo_clear_proxy_pointers_from_lib(oldmain);
index a6474fb50440c1d983cb9216f6bc594bc8feaf20..667550bcaa02a8b3b29371a9d16e97886eaea0b9 100644 (file)
@@ -9275,7 +9275,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                                        simasel->prv_h = 96;
                                                        simasel->prv_w = 96;
                                                        simasel->flag = 7; /* ??? elubie */
-                                                       strcpy (simasel->dir,  U.textudir);     /* TON */
+                                                       BLI_strncpy (simasel->dir,  U.textudir, sizeof(simasel->dir)); /* TON */
                                                        simasel->file[0]= '\0';
                                                        
                                                        simasel->returnfunc     =  NULL;
@@ -9498,7 +9498,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                                                ct= MEM_callocN(sizeof(bConstraintTarget), "PyConTarget");
                                                                
                                                                ct->tar = data->tar;
-                                                               strcpy(ct->subtarget, data->subtarget);
+                                                               BLI_strncpy(ct->subtarget, data->subtarget, sizeof(ct->subtarget));
                                                                ct->space = con->tarspace;
                                                                
                                                                BLI_addtail(&data->targets, ct);
@@ -9528,7 +9528,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                                ct= MEM_callocN(sizeof(bConstraintTarget), "PyConTarget");
                                                
                                                ct->tar = data->tar;
-                                               strcpy(ct->subtarget, data->subtarget);
+                                               BLI_strncpy(ct->subtarget, data->subtarget, sizeof(ct->subtarget));
                                                ct->space = con->tarspace;
                                                
                                                BLI_addtail(&data->targets, ct);
@@ -12008,8 +12008,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                                aa->flag = ia->flag;
                                                aa->sta = ia->sta;
                                                aa->end = ia->end;
-                                               strcpy(aa->name, ia->name);
-                                               strcpy(aa->frameProp, ia->frameProp);
+                                               BLI_strncpy(aa->name, ia->name, sizeof(aa->name));
+                                               BLI_strncpy(aa->frameProp, ia->frameProp, sizeof(aa->frameProp));
                                                if (ob->adt)
                                                        aa->act = ob->adt->action;
 
@@ -13651,8 +13651,8 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
                                                        printf("  enter a new path:\n");
 
                                                        if(scanf("%s", newlib_path) > 0) {
-                                                               strcpy(mainptr->curlib->name, newlib_path);
-                                                               strcpy(mainptr->curlib->filepath, newlib_path);
+                                                               BLI_strncpy(mainptr->curlib->name, newlib_path, sizeof(mainptr->curlib->name));
+                                                               BLI_strncpy(mainptr->curlib->filepath, newlib_path, sizeof(mainptr->curlib->filepath));
                                                                cleanup_path(G.main->name, mainptr->curlib->filepath);
                                                                
                                                                fd= blo_openblenderfile(mainptr->curlib->filepath, basefd->reports);
@@ -13768,7 +13768,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
 
 /* reading runtime */
 
-BlendFileData *blo_read_blendafterruntime(int file, char *name, int actualsize, ReportList *reports)
+BlendFileData *blo_read_blendafterruntime(int file, const char *name, int actualsize, ReportList *reports)
 {
        BlendFileData *bfd = NULL;
        FileData *fd = filedata_new();
index f5308b5ea5c6c4b1d67d37cd1fb6b1e3eed733b4..7a241e007f21d6159cb38697a2af7771c0360ecd 100644 (file)
@@ -68,7 +68,7 @@ static int handle_read_msb_int(int handle)
        return (buf[0]<<24) + (buf[1]<<16) + (buf[2]<<8) + (buf[3]<<0);
 }
 
-int BLO_is_a_runtime(char *path)
+int BLO_is_a_runtime(const char *path)
 {
        int res= 0, fd= open(path, O_BINARY|O_RDONLY, 0);
        int datastart;
@@ -97,7 +97,7 @@ cleanup:
        return res;     
 }
 
-BlendFileData *BLO_read_runtime(char *path, ReportList *reports)
+BlendFileData *BLO_read_runtime(const char *path, ReportList *reports)
 {
        BlendFileData *bfd= NULL;
        size_t actualsize;
index f3a6e2371bb8feb1fc02d93003871388d77a9e76..dec93c0ff636eb0588d031f91d2a314c104c220f 100644 (file)
@@ -691,7 +691,7 @@ void AnimationImporter::apply_matrix_curves( Object * ob, std::vector<FCurve*>&
                if (is_joint)
                        BLI_snprintf(rna_path, sizeof(rna_path), "%s.%s", joint_path, tm_str);
                else
-                       strcpy(rna_path, tm_str);
+                       BLI_strncpy(rna_path, tm_str, sizeof(rna_path));
                newcu[i] = create_fcurve(axis, rna_path);
                newcu[i]->totvert = frames.size();
        }
@@ -1246,7 +1246,7 @@ Object *AnimationImporter::translate_animation_OLD(COLLADAFW::Node *node,
                if (is_joint)
                        BLI_snprintf(rna_path, sizeof(rna_path), "%s.%s", joint_path, tm_str);
                else
-                       strcpy(rna_path, tm_str);
+                       BLI_strncpy(rna_path, tm_str, sizeof(rna_path));
                newcu[i] = create_fcurve(axis, rna_path);
 
 #ifdef ARMATURE_TEST
index 20368bbf57b54e9f51c4c58b34f9888b9210779d..11fd932eed6a0e98deb7fec33db2ebb688e90f4e 100644 (file)
@@ -824,7 +824,7 @@ static void joined_armature_fix_links(Object *tarArm, Object *srcArm, bPoseChann
                                                                }
                                                                else if (strcmp(ct->subtarget, pchan->name)==0) {
                                                                        ct->tar = tarArm;
-                                                                       strcpy(ct->subtarget, curbone->name);
+                                                                       BLI_strncpy(ct->subtarget, curbone->name, sizeof(ct->subtarget));
                                                                }
                                                        }
                                                }
@@ -871,7 +871,7 @@ static void joined_armature_fix_links(Object *tarArm, Object *srcArm, bPoseChann
                                                        }
                                                        else if (strcmp(ct->subtarget, pchan->name)==0) {
                                                                ct->tar = tarArm;
-                                                               strcpy(ct->subtarget, curbone->name);
+                                                               BLI_strncpy(ct->subtarget, curbone->name, sizeof(ct->subtarget));
                                                        }
                                                }
                                        }
@@ -2503,7 +2503,7 @@ void updateDuplicateSubtargetObjects(EditBone *dupBone, ListBase *editbones, Obj
                                                                 */
                                                                if (oldtarget->temp) {
                                                                        newtarget = (EditBone *) oldtarget->temp;
-                                                                       strcpy(ct->subtarget, newtarget->name);
+                                                                       BLI_strncpy(ct->subtarget, newtarget->name, sizeof(ct->subtarget));
                                                                }
                                                        }
                                                }
index bf2e17c4e8787d031058b50f3bd557ba801ff695..e7c7ebf3ecefac253cd4ba8efb24f99c84f21230 100644 (file)
@@ -997,11 +997,8 @@ static void poselib_preview_apply (bContext *C, wmOperator *op)
                        }
                        
                        /* get marker name */
-                       if (pld->marker)
-                               strcpy(markern, pld->marker->name);
-                       else
-                               strcpy(markern, "No Matches");
-                       
+                       BLI_strncpy(markern, pld->marker ? pld->marker->name : "No Matches", sizeof(markern));
+
                        sprintf(pld->headerstr, "PoseLib Previewing Pose: Filter - [%s] | Current Pose - \"%s\"  | Use ScrollWheel or PageUp/Down to change", tempstr, markern);
                        ED_area_headerprint(pld->sa, pld->headerstr);
                }
@@ -1186,7 +1183,7 @@ static int poselib_preview_handle_event (bContext *UNUSED(C), wmOperator *op, wm
        /* backup stuff that needs to occur before every operation
         *      - make a copy of searchstr, so that we know if cache needs to be rebuilt
         */
-       strcpy(pld->searchold, pld->searchstr);
+       BLI_strncpy(pld->searchold, pld->searchstr, sizeof(pld->searchold));
        
        /* if we're currently showing the original pose, only certain events are handled */
        if (pld->flag & PL_PREVIEW_SHOWORIGINAL) {
index b6398c6a2f5f78e2c6066c741a0fe3f61d77156e..5621086459304eb16fcf445cafddcbbcf4ecef2e 100644 (file)
@@ -311,7 +311,7 @@ void copy_gpdata ()
                gpln= MEM_callocN(sizeof(bGPDlayer), "GPCopyPasteLayer");
                
                gpln->frames.first= gpln->frames.last= NULL;
-               strcpy(gpln->info, gpls->info);
+               BLI_strncpy(gpln->info, gpls->info, sizeof(gpln->info));
                
                BLI_addtail(&gpcopybuf, gpln);
                
index 9b9237f70cf708b363ad6d5dd34e09a14016d113..fd511948bac83bc16e8d18dcf969c8ce5695d6e7 100644 (file)
@@ -1151,7 +1151,7 @@ void init_userdef_do_versions(void)
        vDM_ColorBand_store((U.flag & USER_CUSTOM_RANGE) ? (&U.coba_weight):NULL);
 
        if (bmain->versionfile <= 191) {
-               strcpy(U.plugtexdir, U.textudir);
+               BLI_strncpy(U.plugtexdir, U.textudir, sizeof(U.plugtexdir));
                strcpy(U.sounddir, "/");
        }
        
index 6c553289052f5d788d9f4e2b8f655d8f92288ad1..ec7c6cc6108909e5923d56f4a591c7e805c29333 100644 (file)
@@ -245,7 +245,7 @@ static void set_constraint_nth_target (bConstraint *con, Object *target, const c
                for (ct=targets.first, i=0; ct; ct= ct->next, i++) {
                        if (i == index) {
                                ct->tar= target;
-                               strcpy(ct->subtarget, subtarget);
+                               BLI_strncpy(ct->subtarget, subtarget, sizeof(ct->subtarget));
                                break;
                        }
                }
index 389c0941cc247995981e5020f06976bf25976e29..49a71018719c96cffedb0e9793e88ead69ae2930 100644 (file)
@@ -334,11 +334,9 @@ static int make_proxy_exec (bContext *C, wmOperator *op)
                
                /* Add new object for the proxy */
                newob= add_object(scene, OB_EMPTY);
-               if (gob)
-                       strcpy(name, gob->id.name+2);
-               else
-                       strcpy(name, ob->id.name+2);
-               strcat(name, "_proxy");
+
+               BLI_snprintf(name, sizeof(name), "%s_proxy", ((ID *)(gob ? gob : ob))->name);
+
                rename_id(&newob->id, name);
                
                /* set layers OK */
@@ -605,7 +603,7 @@ static int parent_set_exec(bContext *C, wmOperator *op)
                                
                                /* handle types */
                                if (pchan)
-                                       strcpy(ob->parsubstr, pchan->name);
+                                       BLI_strncpy(ob->parsubstr, pchan->name, sizeof(ob->parsubstr));
                                else
                                        ob->parsubstr[0]= 0;
                                        
index 7b4db3473155e8036c5c422907f00bf6097ef323..c1b21865504678faeb3d582e763a11cd6231a6a9 100644 (file)
@@ -669,7 +669,7 @@ static void vgroup_duplicate(Object *ob)
        }
 
        cdg = defgroup_duplicate(dg);
-       strcpy(cdg->name, name);
+       BLI_strncpy(cdg->name, name, sizeof(cdg->name));
        defgroup_unique_name(cdg, ob);
 
        BLI_addtail(&ob->defbase, cdg);
index 70709a22d3da468a03051c1242fa600e32f19d8e..697cddfcee0a5d6b415e67f224dcce35acb3a4b3 100644 (file)
@@ -261,7 +261,7 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                        sce->r.alphamode= R_ADDSKY;
 
                sce->r.cfra= scene->r.cfra;
-               strcpy(sce->r.engine, scene->r.engine);
+               BLI_strncpy(sce->r.engine, scene->r.engine, sizeof(sce->r.engine));
                
                if(id_type==ID_MA) {
                        Material *mat= NULL, *origmat= (Material *)id;
index 3010adafe20d0c21da07614814ac4852dd0e1a69..27c311aa04f403a5792ebef5a445b057e865cff0 100644 (file)
@@ -157,7 +157,7 @@ static int screenshot_exec(bContext *C, wmOperator *op)
 
                        RNA_string_get(op->ptr, "filepath", path);
 
-                       strcpy(G.ima, path);
+                       BLI_strncpy(G.ima, path, sizeof(G.ima));
                        BLI_path_abs(path, G.main->name);
 
                        /* BKE_add_image_extension() checks for if extension was already set */
index c5af89719072fc1062f37aa1ae7af694e6874c9e..b6b22c391b8131f5d146c157a714cf732665dc2d 100644 (file)
@@ -401,7 +401,7 @@ static void *image_undo_push_tile(Image *ima, ImBuf *ibuf, ImBuf **tmpibuf, int
                *tmpibuf = IMB_allocImBuf(IMAPAINT_TILE_SIZE, IMAPAINT_TILE_SIZE, 32, IB_rectfloat|IB_rect);
        
        tile= MEM_callocN(sizeof(UndoImageTile), "UndoImageTile");
-       strcpy(tile->idname, ima->id.name);
+       BLI_strncpy(tile->idname, ima->id.name, sizeof(tile->idname));
        tile->x= x_tile;
        tile->y= y_tile;
 
@@ -409,7 +409,7 @@ static void *image_undo_push_tile(Image *ima, ImBuf *ibuf, ImBuf **tmpibuf, int
        allocsize *= (ibuf->rect_float)? sizeof(float): sizeof(char);
        tile->rect= MEM_mapallocN(allocsize, "UndeImageTile.rect");
 
-       strcpy(tile->ibufname, ibuf->name);
+       BLI_strncpy(tile->ibufname, ibuf->name, sizeof(tile->ibufname));
 
        tile->gen_type= ima->gen_type;
        tile->source= ima->source;
index 13b6fef30047f0c5dbcb2ae4c23b5426140dfa08..a32487e7117862ca963ecc95aa699e4edbe3662e 100644 (file)
@@ -262,7 +262,7 @@ SculptUndoNode *sculpt_undo_push_node(Object *ob, PBVHNode *node)
        }
 
        unode= MEM_callocN(sizeof(SculptUndoNode), "SculptUndoNode");
-       strcpy(unode->idname, ob->id.name);
+       BLI_strncpy(unode->idname, ob->id.name, sizeof(unode->idname));
        unode->node= node;
 
        BLI_pbvh_node_num_verts(ss->pbvh, node, &totvert, &allvert);
index 7fa4e62359ae8600ff528620cf26c00b32587395..7e4d02036ef316666505607c822fcc90f9b02db9 100644 (file)
@@ -235,7 +235,7 @@ static int sequencer_add_scene_strip_exec(bContext *C, wmOperator *op)
        
        strip->stripdata= MEM_callocN(seq->len*sizeof(StripElem), "stripelem");
        
-       strcpy(seq->name+2, sce_seq->id.name+2);
+       BLI_strncpy(seq->name+2, sce_seq->id.name+2, sizeof(seq->name)-2);
        seqbase_unique_name_recursive(&ed->seqbase, seq);
 
        seq->scene_sound = sound_scene_add_scene_sound(scene, seq, start_frame, start_frame + strip->len, 0);
index 45543a9313ee833d6bae4885d25399c40fbf547d..33d2a27f789d623f37f2c74cbec51a22ba71fa65 100644 (file)
@@ -929,11 +929,11 @@ static void UNUSED_FUNCTION(seq_remap_paths)(Scene *scene)
        if(last_seq==NULL) 
                return;
        
-       BLI_strncpy(from, last_seq->strip->dir, FILE_MAX);
+       BLI_strncpy(from, last_seq->strip->dir, sizeof(from));
 // XXX if (0==sbutton(from, 0, sizeof(from)-1, "From: "))
 //             return;
        
-       strcpy(to, from);
+       BLI_strncpy(to, from, sizeof(to));
 // XXX if (0==sbutton(to, 0, sizeof(to)-1, "To: "))
 //             return;
        
index c1ef8c4792b2ad0499fdd38f91fc85e97c233012..34c39b1083a483811814c2ebe2545308a7bf7c15 100644 (file)
@@ -1175,7 +1175,7 @@ static struct ImBuf * anim_getnew(struct anim * anim) {
        case ANIM_SEQUENCE:
                ibuf = IMB_loadiffname(anim->name, anim->ib_flags);
                if (ibuf) {
-                       strcpy(anim->first, anim->name);
+                       BLI_strncpy(anim->first, anim->name, sizeof(anim->first));
                        anim->duration = 1;
                }
                break;
index 2a81c4f0a2cfde7326a2186f271be0e3a80e7cfe..f30fea659ae87f91af211c5c1611ae29df014972 100644 (file)
@@ -179,10 +179,11 @@ static void rna_Lattice_points_w_set(PointerRNA *ptr, int value)
 static void rna_Lattice_vg_name_set(PointerRNA *ptr, const char *value)
 {
        Lattice *lt= ptr->data;
-       strcpy(lt->vgroup, value);
+       BLI_strncpy(lt->vgroup, value, sizeof(lt->vgroup));
 
-       if(lt->editlatt)
-               strcpy(lt->editlatt->latt->vgroup, value);
+       if(lt->editlatt) {
+               BLI_strncpy(lt->editlatt->latt->vgroup, value, sizeof(lt->editlatt->latt->vgroup));
+       }
 }
 
 /* annoying, but is a consequence of RNA structures... */
index c36dca22731ceaaa6f40d91752cadef0b29c204c..8db1faee04d073b486c8e3a35802c11b7ed8da84 100644 (file)
@@ -193,7 +193,7 @@ static void rna_Cache_idname_change(Main *UNUSED(bmain), Scene *UNUSED(scene), P
                                pid2 = pid;
                        else if(cache->name[0] != '\0' && strcmp(cache->name,pid->cache->name)==0) {
                                /*TODO: report "name exists" to user */
-                               strcpy(cache->name, cache->prev_name);
+                               BLI_strncpy(cache->name, cache->prev_name, sizeof(cache->name));
                                new_name = 0;
                        }
                }
@@ -203,13 +203,13 @@ static void rna_Cache_idname_change(Main *UNUSED(bmain), Scene *UNUSED(scene), P
                                char old_name[80];
                                char new_name[80];
 
-                               strcpy(old_name, cache->prev_name);
-                               strcpy(new_name, cache->name);
+                               BLI_strncpy(old_name, cache->prev_name, sizeof(old_name));
+                               BLI_strncpy(new_name, cache->name, sizeof(new_name));
 
                                BKE_ptcache_disk_cache_rename(pid2, old_name, new_name);
                        }
 
-                       strcpy(cache->prev_name, cache->name);
+                       BLI_strncpy(cache->prev_name, cache->name, sizeof(cache->prev_name));
                }
        }
 
index 757da28e4b598c894626345c7d26da09b17f800a..f2e3a0d016a8d748c40b79409d5f9a7547918921 100644 (file)
@@ -40,6 +40,7 @@
 #include "BLI_math.h"
 #include "BLI_edgehash.h"
 #include "BLI_utildefines.h"
+#include "BLI_string.h"
 
 #include "BKE_cdderivedmesh.h"
 #include "BKE_mesh.h"
@@ -183,7 +184,7 @@ static void copyData(ModifierData *md, ModifierData *target)
        tsmd->crease_outer = smd->crease_outer;
        tsmd->crease_rim = smd->crease_rim;
        tsmd->flag = smd->flag;
-       strcpy(tsmd->defgrp_name, smd->defgrp_name);
+       BLI_strncpy(tsmd->defgrp_name, smd->defgrp_name, sizeof(tsmd->defgrp_name));
 }
 
 static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
index 4dbf4b96b741d6d468560aa42daaeeea6d15aad9..6214f39dc0a6809f1f4d446470d7360765aa129c 100644 (file)
@@ -718,7 +718,7 @@ static bNodeSocket *group_verify_socket(bNodeTree *ntree, ListBase *lb, int in_o
        if(sock) {
                sock->groupsock = gsock;
                
-               strcpy(sock->name, gsock->name);
+               BLI_strncpy(sock->name, gsock->name, sizeof(sock->name));
                sock->type= gsock->type;
                
                /* XXX hack: group socket input/output roles are inverted internally,
@@ -903,7 +903,7 @@ static void loop_sync(bNodeTree *ntree, int sync_in_out)
                                        if (mirror->own_index == GET_INT_FROM_POINTER(sock->storage))
                                                break;
                                /* make sure the name is the same (only for identification by user, no deeper meaning) */
-                               strcpy(mirror->name, sock->name);
+                               BLI_strncpy(mirror->name, sock->name, sizeof(mirror->name));
                                /* fix the socket order if necessary */
                                if (mirror != sync) {
                                        BLI_remlink(sync_lb, mirror);
index 7a39342ac8d667dedf880cafee7cd24df4fbd827..a73bf93841d0e988fd30be1bb5e3bd38fed62e75 100644 (file)
@@ -481,12 +481,12 @@ void RE_set_customdata_names(ObjectRen *obr, CustomData *data)
                layer= &data->layers[i];
 
                if (layer->type == CD_MTFACE) {
-                       strcpy(obr->mtface[mtfn++], layer->name);
+                       BLI_strncpy(obr->mtface[mtfn++], layer->name, sizeof(layer->name));
                        obr->actmtface= CLAMPIS(layer->active_rnd, 0, numtf);
                        obr->bakemtface= layer->active;
                }
                else if (layer->type == CD_MCOL) {
-                       strcpy(obr->mcol[mcn++], layer->name);
+                       BLI_strncpy(obr->mcol[mcn++], layer->name, sizeof(layer->name));
                        obr->actmcol= CLAMPIS(layer->active_rnd, 0, numcol);
                }
        }
index f5bd3a91c265c4a7a4b17c829ab7dd3b7dd3403f..ea17b9adcfd73e7484a9eb010199885d0bb770f1 100644 (file)
@@ -309,7 +309,7 @@ static void get_filename(int argc, char **argv, char *filename)
 #endif // !_APPLE
 }
 
-static BlendFileData *load_game_data(char *progname, char *filename = NULL, char *relativename = NULL)
+static BlendFileData *load_game_data(const char *progname, char *filename = NULL, char *relativename = NULL)
 {
        ReportList reports;
        BlendFileData *bfd = NULL;
@@ -321,7 +321,7 @@ static BlendFileData *load_game_data(char *progname, char *filename = NULL, char
                bfd= BLO_read_runtime(progname, &reports);
                if (bfd) {
                        bfd->type= BLENFILETYPE_RUNTIME;
-                       strcpy(bfd->main->name, progname);
+                       BLI_strncpy(bfd->main->name, progname, sizeof(bfd->main->name));
                }
        } else {
                bfd= BLO_read_from_file(progname, &reports);
@@ -766,7 +766,7 @@ int main(int argc, char** argv)
                                                char basedpath[240];
                                                
                                                // base the actuator filename relative to the last file
-                                               strcpy(basedpath, exitstring.Ptr());
+                                               BLI_strncpy(basedpath, exitstring.Ptr(), sizeof(basedpath));
                                                BLI_path_abs(basedpath, pathname);
                                                
                                                bfd = load_game_data(basedpath);