Cleanup: avoid member access within null pointer

While harmless, UBSan warns about this.
Prefer offsetof where possible since it's more readable.
This commit is contained in:
Ankit Meel 2020-10-01 14:47:13 +10:00 committed by Campbell Barton
parent c1ae12bf5e
commit 99fb853734
1 changed files with 2 additions and 1 deletions

View File

@ -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 */