bugfix, off by 1 error when filling in uninitialized values for new ID values when the requested name length was greater to or equal to 21.

Also replaced incorrect use of strcpy with memmove since the strings overlap
This commit is contained in:
2008-06-11 09:04:41 +00:00
parent bdb3ef08cf
commit ef0ea178b1
2 changed files with 17 additions and 7 deletions

View File

@@ -934,7 +934,7 @@ int new_id(ListBase *lb, ID *id, const char *tname)
}
/* if result > 21, strncpy don't put the final '\0' to name. */
if( result > 21 ) name[21]= 0;
if( result >= 21 ) name[21]= 0;
result = check_for_dupid( lb, id, name );
strcpy( id->name+2, name );

View File

@@ -883,6 +883,15 @@ void BLI_cleanup_file(const char *relabase, char *dir)
dir = dir+2; /* skip the first // */
}
}
/* Note
* memmove( start, eind, strlen(eind)+1 );
* is the same as
* strcpy( start, eind );
* except strcpy should not be used because there is overlap,
* so use memmove's slightly more obscure syntax - Campbell
*/
#ifdef WIN32
if(dir[0]=='.') { /* happens for example in FILE_MAIN */
get_default_root(dir);
@@ -896,17 +905,18 @@ void BLI_cleanup_file(const char *relabase, char *dir)
if (dir[a] == '\\') break;
a--;
}
strcpy(dir+a,eind);
memmove( dir+a, eind, strlen(eind)+1 );
}
while ( (start = strstr(dir,"\\.\\")) ){
eind = start + strlen("\\.\\") - 1;
strcpy(start,eind);
memmove( start, eind, strlen(eind)+1 );
}
while ( (start = strstr(dir,"\\\\" )) ){
eind = start + strlen("\\\\") - 1;
strcpy(start,eind);
memmove( start, eind, strlen(eind)+1 );
}
if((a = strlen(dir))){ /* remove the '\\' at the end */
@@ -929,17 +939,17 @@ void BLI_cleanup_file(const char *relabase, char *dir)
if (dir[a] == '/') break;
a--;
}
strcpy(dir+a,eind);
memmove( dir+a, eind, strlen(eind)+1 );
}
while ( (start = strstr(dir,"/./")) ){
eind = start + strlen("/./") - 1;
strcpy(start,eind);
memmove( start, eind, strlen(eind)+1 );
}
while ( (start = strstr(dir,"//" )) ){
eind = start + strlen("//") - 1;
strcpy(start,eind);
memmove( start, eind, strlen(eind)+1 );
}
if( (a = strlen(dir)) ){ /* remove all '/' at the end */