From 6dd1643a701c45fa779ea6da180f120c36c31a97 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 31 Dec 2017 23:19:41 -0800 Subject: Avoid dereferencing a NULL pointer Even though it's taking the address of a member, it's still technically a derefernce and thus undefined behavior. sizeof doesn't "execute" the expression, so derefering in it instead is fine. --- Alc/vector.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Alc') diff --git a/Alc/vector.h b/Alc/vector.h index ed0780e3..ed9acfb0 100644 --- a/Alc/vector.h +++ b/Alc/vector.h @@ -37,7 +37,8 @@ typedef const _##N* const_##N; \ if(((_x) ? (_x)->Capacity : 0) < _cap) \ { \ - ptrdiff_t data_offset = (char*)((_x)->Data) - (char*)(_x); \ + ptrdiff_t data_offset = (_x) ? (char*)((_x)->Data) - (char*)(_x) : \ + sizeof(*(_x)); \ size_t old_size = ((_x) ? (_x)->Size : 0); \ void *temp; \ \ -- cgit v1.2.3