Cleanup & fix potential NULL pointer dereferencing.
authorBastien Montagne <montagne29@wanadoo.fr>
Thu, 10 Aug 2017 08:27:47 +0000 (10:27 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Thu, 10 Aug 2017 08:28:13 +0000 (10:28 +0200)
source/blender/blenkernel/intern/library.c

index 0ccf67e7f8ef24d1a406f1f335bff1c9aa11f47e..a1bd410d390eb875495a4e88dd1c5e8c2f57da3d 100644 (file)
@@ -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;
                }