From 4cfac9edab8e74982aec1a57541167751c59ac4f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 30 Mar 2017 22:52:12 +0200 Subject: Cleanup/fix bad code in IDP_SetIndexArray() Mainly, using index before checking for its validity... --- source/blender/blenkernel/intern/idprop.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'source/blender/blenkernel/intern/idprop.c') diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index b2641b110f8..a596869e5e8 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -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) -- cgit v1.2.3