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-07-23 08:41:27 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-07-23 08:41:27 +0400
commitbd30c4da8aeb164d9276beffe09a2a18a5c90523 (patch)
treec2529968b7db61a3ed4c3a3ed704a062c9f4d182 /source/blender/blenkernel/intern/library.c
parent026ac2492232fac4fb7350ff210ba34b353a84e2 (diff)
[#22876] Add new scene, stacker ".00" bug
fix for r30441, (reverted for the beta), splitIDname wasnt returning the correct string length.
Diffstat (limited to 'source/blender/blenkernel/intern/library.c')
-rw-r--r--source/blender/blenkernel/intern/library.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index fdc98d9ed29..acfaef9eb88 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -995,7 +995,7 @@ void IMAnames_to_pupstring(char **str, char *title, char *extraops, ListBase *lb
/* used by buttons.c library.c mball.c */
-void splitIDname(char *name, char *left, int *nr)
+int splitIDname(char *name, char *left, int *nr)
{
int a;
@@ -1003,19 +1003,23 @@ void splitIDname(char *name, char *left, int *nr)
strncpy(left, name, 21);
a= strlen(name);
- if(a>1 && name[a-1]=='.') return;
+ if(a>1 && name[a-1]=='.') return a;
while(a--) {
if( name[a]=='.' ) {
left[a]= 0;
*nr= atol(name+a+1);
- return;
+ return a;
}
if( isdigit(name[a])==0 ) break;
left[a]= 0;
}
- strcpy(left, name);
+
+ for(a= 0; name[a]; a++)
+ left[a]= name[a];
+
+ return a;
}
static void sort_alpha_id(ListBase *lb, ID *id)
@@ -1077,8 +1081,7 @@ static ID *is_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;
+ int nr= 0, nrtest, a, left_len;
char left[32], leftest[32], in_use[32];
/* make sure input name is terminated properly */
@@ -1095,31 +1098,31 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name)
/* we have a dup; need to make a new name */
/* quick check so we can reuse one of first 32 ids if vacant */
- memset(in_use, 0, maxtest);
+ memset(in_use, 0, sizeof(in_use));
/* get name portion, number portion ("name.number") */
- splitIDname( name, left, &nr);
+ left_len= splitIDname(name, left, &nr);
/* if new name will be too long, truncate it */
if(nr>999 && strlen(left)>16) left[16]= 0;
else if(strlen(left)>17) left[17]= 0;
- for( idtest = lb->first; idtest; idtest = idtest->next ) {
- if( id != idtest && idtest->lib == NULL ) {
- splitIDname(idtest->name+2, leftest, &nrtest);
- /* if base names match... */
- /* optimized */
- if( *left == *leftest && strcmp(left, leftest)==0 ) {
- if(nrtest < maxtest)
- in_use[nrtest]= 1; /* mark as used */
- if(nr <= nrtest)
- nr= nrtest+1; /* track largest unused */
- }
+ for(idtest= lb->first; idtest; idtest= idtest->next) {
+ if( (id != idtest) &&
+ (idtest->lib == NULL) &&
+ (*name == *(idtest->name+2)) &&
+ (strncmp(name, idtest->name+2, left_len)==0) &&
+ (splitIDname(idtest->name+2, leftest, &nrtest) == left_len)
+ ) {
+ if(nrtest < sizeof(in_use))
+ in_use[nrtest]= 1; /* mark as used */
+ if(nr <= nrtest)
+ nr= nrtest+1; /* track largest unused */
}
}
/* decide which value of nr to use */
- for(a=0; a<maxtest; a++) {
+ for(a=0; a < sizeof(in_use); a++) {
if(a>=nr) break; /* stop when we've check up to biggest */
if( in_use[a]==0 ) { /* found an unused value */
nr = a;
@@ -1129,8 +1132,9 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name)
/* If the original name has no numeric suffix,
* rather than just chopping and adding numbers,
- * shave off the end chars until we have a unique name */
- if (nr==0) {
+ * shave off the end chars until we have a unique name.
+ * Check the null terminators match as well so we dont get Cube.000 -> Cube.00 */
+ if (nr==0 && name[left_len]== left[left_len]) {
int len = strlen(name)-1;
idtest= is_dupid(lb, id, name);
@@ -1389,4 +1393,3 @@ void rename_id(ID *id, char *name)
new_id(lb, id, name);
}
-