Fix possible segfault in blender.

tname can be bigger of 21 character, in that case
strncpy don't put the final '\0' to the name this.
This commit is contained in:
Diego Borghetti 2007-06-06 15:11:16 +00:00
parent 9a78468ab0
commit ee0c3245e7

@ -915,12 +915,17 @@ int new_id(ListBase *lb, ID *id, const char *tname)
/* 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 */
if(tname==0) { /* if no name given, use name of current ID */
strncpy(name, id->name+2, 21);
else /* else make a copy (tname args can be const) */
result= strlen(id->name+2);
}
else { /* else make a copy (tname args can be const) */
strncpy(name, tname, 21);
result= strlen(tname);
}
if( strlen(name) > 21 ) name[21]= 0;
/* if result > 21, strncpy don't put the final '\0' to name. */
if( result > 21 ) name[21]= 0;
result = check_for_dupid( lb, id, name );
strcpy( id->name+2, name );