From cf7a2c93e3a897a3300bc7df527c8ba271da0424 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 10 Aug 2017 10:27:47 +0200 Subject: [PATCH] Cleanup & fix potential NULL pointer dereferencing. --- source/blender/blenkernel/intern/library.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 0ccf67e7f8e..a1bd410d390 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -1099,22 +1099,20 @@ void *BKE_libblock_alloc_notest(short type) */ void *BKE_libblock_alloc(Main *bmain, short type, const char *name, const int flag) { - ID *id = NULL; - BLI_assert((flag & LIB_ID_CREATE_NO_ALLOCATE) == 0); - - id = BKE_libblock_alloc_notest(type); - if ((flag & LIB_ID_CREATE_NO_MAIN) != 0) { - id->tag |= LIB_TAG_NO_MAIN; - } - if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) != 0) { - id->tag |= LIB_TAG_NO_USER_REFCOUNT; - } + ID *id = BKE_libblock_alloc_notest(type); if (id) { + if ((flag & LIB_ID_CREATE_NO_MAIN) != 0) { + id->tag |= LIB_TAG_NO_MAIN; + } + if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) != 0) { + id->tag |= LIB_TAG_NO_USER_REFCOUNT; + } + id->icon_id = 0; - *( (short *)id->name) = type; + *((short *)id->name) = type; if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { id->us = 1; }