Cleanup/fix bad code in IDP_SetIndexArray()

Mainly, using index before checking for its validity...
This commit is contained in:
Bastien Montagne 2017-03-30 22:52:12 +02:00
parent 5b3b0b4778
commit 4cfac9edab
1 changed files with 9 additions and 5 deletions

View File

@ -130,18 +130,22 @@ void IDP_FreeIDPArray(IDProperty *prop)
MEM_freeN(prop->data.pointer);
}
/*shallow copies item*/
/* shallow copies item */
void IDP_SetIndexArray(IDProperty *prop, int index, IDProperty *item)
{
IDProperty *old;
BLI_assert(prop->type == IDP_IDPARRAY);
if (index >= prop->len || index < 0)
return;
old = GETPROP(prop, index);
if (index >= prop->len || index < 0) return;
if (item != old) IDP_FreeProperty(old);
memcpy(GETPROP(prop, index), item, sizeof(IDProperty));
if (item != old) {
IDP_FreeProperty(old);
memcpy(old, item, sizeof(IDProperty));
}
}
IDProperty *IDP_GetIndexArray(IDProperty *prop, int index)