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-03-06 21:21:57 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-03-06 21:21:57 +0300
commitc0f56503bf6fcd92a65a8b05466c5093e083c96a (patch)
tree58d4692d5a25dbcd1af5779a075c2caf5b49679f /source/blender/blenkernel/intern/library.c
parentc846136cd01e16c11fb42caf5b9ceaef41e3c64c (diff)
disallow naming ID datablocks an empty string, this wont work, you cant select them in the ID user input and it can mess up writing files based on names.
also fixed some warnings.
Diffstat (limited to 'source/blender/blenkernel/intern/library.c')
-rw-r--r--source/blender/blenkernel/intern/library.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 3ea36450b80..79bc92bdbfb 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -1093,15 +1093,16 @@ static ID *is_dupid(ListBase *lb, ID *id, char *name)
* id is NULL;
*/
-int check_for_dupid(ListBase *lb, ID *id, char *name)
+static int check_for_dupid(ListBase *lb, ID *id, char *name)
{
ID *idtest;
int nr= 0, nrtest, a;
const int maxtest=32;
char left[32], leftest[32], in_use[32];
-
+
/* make sure input name is terminated properly */
- if( strlen(name) > 21 ) name[21]= 0;
+ /* if( strlen(name) > 21 ) name[21]= 0; */
+ /* removed since this is only ever called from one place - campbell */
while (1) {
@@ -1184,27 +1185,29 @@ int new_id(ListBase *lb, ID *id, const char *tname)
{
int result;
char name[22];
-
+
/* if library, don't rename */
if(id->lib) return 0;
/* if no libdata given, look up based on ID */
if(lb==NULL) lb= wich_libbase(G.main, GS(id->name));
- if(tname==0) { /* if no name given, use name of current ID */
- strncpy(name, id->name+2, 21);
- result= strlen(id->name+2);
- }
- else { /* else make a copy (tname args can be const) */
- strncpy(name, tname, 21);
- result= strlen(tname);
- }
+ /* if no name given, use name of current ID
+ * else make a copy (tname args can be const) */
+ if(tname==NULL)
+ tname= id->name+2;
+
+ strncpy(name, tname, sizeof(name)-1);
+
+ /* if result > 21, strncpy don't put the final '\0' to name.
+ * easier to assign each time then to check if its needed */
+ name[sizeof(name)-1]= 0;
- /* if result > 21, strncpy don't put the final '\0' to name. */
- if( result >= 21 ) name[21]= 0;
+ if(name[0] == '\0')
+ strcpy(name, ID_FALLBACK_NAME);
- result = check_for_dupid( lb, id, name );
- strcpy( id->name+2, name );
+ result = check_for_dupid(lb, id, name);
+ strcpy(id->name+2, name);
/* This was in 2.43 and previous releases
* however all data in blender should be sorted, not just duplicate names
@@ -1393,7 +1396,7 @@ void text_idbutton(struct ID *id, char *text)
void rename_id(ID *id, char *name)
{
ListBase *lb;
-
+
strncpy(id->name+2, name, 21);
lb= wich_libbase(G.main, GS(id->name) );