[Bf-blender-cvs] [99fb853734c] master: Cleanup: avoid member access within null pointer

Ankit Meel noreply at git.blender.org
Thu Oct 1 06:51:28 CEST 2020


Commit: 99fb853734cba8b778f9e60789ef51bd638d35da
Author: Ankit Meel
Date:   Thu Oct 1 14:47:13 2020 +1000
Branches: master
https://developer.blender.org/rB99fb853734cba8b778f9e60789ef51bd638d35da

Cleanup: avoid member access within null pointer

While harmless, UBSan warns about this.
Prefer offsetof where possible since it's more readable.

===================================================================

M	intern/guardedalloc/intern/mallocn_guarded_impl.c

===================================================================

diff --git a/intern/guardedalloc/intern/mallocn_guarded_impl.c b/intern/guardedalloc/intern/mallocn_guarded_impl.c
index 6c08cb3bb62..6a0d104d47d 100644
--- a/intern/guardedalloc/intern/mallocn_guarded_impl.c
+++ b/intern/guardedalloc/intern/mallocn_guarded_impl.c
@@ -24,6 +24,7 @@
  */
 
 #include <stdarg.h>
+#include <stddef.h> /* offsetof */
 #include <stdlib.h>
 #include <string.h> /* memcpy */
 #include <sys/types.h>
@@ -153,7 +154,7 @@ static const char *check_memlist(MemHead *memh);
 #define MEMTAG3 MAKE_ID('O', 'C', 'K', '!')
 #define MEMFREE MAKE_ID('F', 'R', 'E', 'E')
 
-#define MEMNEXT(x) ((MemHead *)(((char *)x) - ((char *)&(((MemHead *)0)->next))))
+#define MEMNEXT(x) ((MemHead *)(((char *)x) - offsetof(MemHead, next)))
 
 /* --------------------------------------------------------------------- */
 /* vars                                                                  */



More information about the Bf-blender-cvs mailing list