From 13d7d6fe9574e0c19efdbbe8e0c25193fc94bc12 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 1 Apr 2017 03:00:24 -0700 Subject: [PATCH] Don't rely on sizeof being the offset to a struct's unsized array --- Alc/vector.h | 5 +++-- 1 file 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)); \ -- 2.11.4.GIT