aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/vector.h
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2017-04-01 03:00:24 -0700
committerChris Robinson <[email protected]>2017-04-01 03:00:24 -0700
commit13d7d6fe9574e0c19efdbbe8e0c25193fc94bc12 (patch)
tree4c266294bdadf6b89a6ac9c1bdb9cbcb05affb5c /Alc/vector.h
parent52112b0b8d796aa1617a560288ab12dd027fd99b (diff)
Don't rely on sizeof being the offset to a struct's unsized array
Diffstat (limited to 'Alc/vector.h')
-rw-r--r--Alc/vector.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/Alc/vector.h b/Alc/vector.h
index 4bb92458..8af8b40c 100644
--- a/Alc/vector.h
+++ b/Alc/vector.h
@@ -37,13 +37,14 @@ typedef const _##N* const_##N;
\
if(((_x) ? (_x)->Capacity : 0) < _cap) \
{ \
+ ptrdiff_t data_offset = (char*)((_x)->Data) - (char*)(_x); \
size_t old_size = ((_x) ? (_x)->Size : 0); \
void *temp; \
\
- temp = al_calloc(16, sizeof(*(_x)) + sizeof((_x)->Data[0])*_cap); \
+ temp = al_calloc(16, data_offset + sizeof((_x)->Data[0])*_cap); \
assert(temp != NULL); \
if((_x)) \
- memcpy(((ALubyte*)temp)+sizeof(*(_x)), (_x)->Data, \
+ memcpy(((char*)temp)+data_offset, (_x)->Data, \
sizeof((_x)->Data[0])*old_size); \
\
al_free((_x)); \