diff options
-rw-r--r-- | Alc/ALc.c | 6 | ||||
-rw-r--r-- | Alc/ALu.c | 2 | ||||
-rw-r--r-- | Alc/converter.c | 2 | ||||
-rw-r--r-- | Alc/hrtf.c | 4 | ||||
-rw-r--r-- | Alc/panning.c | 4 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 6 | ||||
-rw-r--r-- | OpenAL32/alAuxEffectSlot.c | 8 | ||||
-rw-r--r-- | OpenAL32/alSource.c | 2 |
8 files changed, 17 insertions, 17 deletions
@@ -2501,7 +2501,7 @@ static ALvoid InitContext(ALCcontext *Context) InitUIntMap(&Context->SourceMap, Context->Device->SourcesMax); InitUIntMap(&Context->EffectSlotMap, Context->Device->AuxiliaryEffectSlotMax); - auxslots = al_calloc(DEF_ALIGN, offsetof(struct ALeffectslotArray, slot[0])); + auxslots = al_calloc(DEF_ALIGN, sizeof(struct ALeffectslotArray)); auxslots->count = 0; ATOMIC_INIT(&Context->ActiveAuxSlots, auxslots); @@ -2725,8 +2725,8 @@ void AllocateVoices(ALCcontext *context, ALsizei num_voices, ALsizei old_sends) * property set (including the dynamically-sized Send[] array) in one * chunk. */ - sizeof_props = RoundUp(offsetof(struct ALvoiceProps, Send[num_sends]), 16); - sizeof_voice = RoundUp(offsetof(ALvoice, Send[num_sends]), 16); + sizeof_props = RoundUp(FAM_SIZE(struct ALvoiceProps, Send, num_sends), 16); + sizeof_voice = RoundUp(FAM_SIZE(ALvoice, Send, num_sends), 16); size = sizeof(ALvoice*) + sizeof_voice + sizeof_props; voices = al_calloc(16, RoundUp(size*num_voices, 16)); @@ -1283,7 +1283,7 @@ static void CalcSourceParams(ALvoice *voice, ALCcontext *context, ALboolean forc if(props) { memcpy(voice->Props, props, - offsetof(struct ALvoiceProps, Send[context->Device->NumAuxSends]) + FAM_SIZE(struct ALvoiceProps, Send, context->Device->NumAuxSends) ); ATOMIC_REPLACE_HEAD(struct ALvoiceProps*, &voice->FreeList, props); diff --git a/Alc/converter.c b/Alc/converter.c index 99069d15..f1a3a96b 100644 --- a/Alc/converter.c +++ b/Alc/converter.c @@ -13,7 +13,7 @@ SampleConverter *CreateSampleConverter(enum DevFmtType srcType, enum DevFmtType if(numchans <= 0 || srcRate <= 0 || dstRate <= 0) return NULL; - converter = al_calloc(16, offsetof(SampleConverter, Chan[numchans])); + converter = al_calloc(16, FAM_SIZE(SampleConverter, Chan, numchans)); converter->mSrcType = srcType; converter->mDstType = dstType; converter->mNumChannels = numchans; @@ -688,7 +688,7 @@ static void AddFileEntry(vector_EnumeratedHrtf *list, const_al_string filename) TRACE("Got new file \"%s\"\n", alstr_get_cstr(filename)); loaded_entry = al_calloc(DEF_ALIGN, - offsetof(struct HrtfEntry, filename[alstr_length(filename)+1]) + FAM_SIZE(struct HrtfEntry, filename, alstr_length(filename)+1) ); loaded_entry->next = LoadedHrtfs; loaded_entry->handle = NULL; @@ -769,7 +769,7 @@ static void AddBuiltInEntry(vector_EnumeratedHrtf *list, const_al_string filenam TRACE("Got new file \"%s\"\n", alstr_get_cstr(filename)); loaded_entry = al_calloc(DEF_ALIGN, - offsetof(struct HrtfEntry, filename[namelen]) + FAM_SIZE(struct HrtfEntry, filename, namelen) ); loaded_entry->next = LoadedHrtfs; loaded_entry->handle = hrtf; diff --git a/Alc/panning.c b/Alc/panning.c index e4941720..5ce93b9b 100644 --- a/Alc/panning.c +++ b/Alc/panning.c @@ -922,13 +922,11 @@ static void InitHrtfPanning(ALCdevice *device, bool hoa_mode) }; const ALfloat (*AmbiMatrix)[2][MAX_AMBI_COEFFS] = hoa_mode ? AmbiMatrixHOA : AmbiMatrixFOA; ALsizei count = hoa_mode ? 9 : 4; - size_t sizeof_hrtfstate; ALsizei i; static_assert(COUNTOF(AmbiPoints) <= HRTF_AMBI_MAX_CHANNELS, "HRTF_AMBI_MAX_CHANNELS is too small"); - sizeof_hrtfstate = offsetof(DirectHrtfState, Chan[count]); - device->Hrtf = al_calloc(16, sizeof_hrtfstate); + device->Hrtf = al_calloc(16, FAM_SIZE(DirectHrtfState, Chan, count)); for(i = 0;i < count;i++) { diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 191bb658..3a8aabde 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -225,6 +225,12 @@ typedef ALuint64SOFT ALuint64; #define DECL_FORMAT(x, y, z) #endif +/* Calculates the size of a struct with N elements of a flexible array member. + * GCC and Clang allow offsetof(Type, fam[N]) for this, but MSVC seems to have + * trouble, so a bit more verbose workaround is needed. + */ +#define FAM_SIZE(T, M, N) (offsetof(T, M) + sizeof(((T*)NULL)->M[0])*(N)) + #if defined(__GNUC__) && defined(__i386__) /* force_align_arg_pointer is required for proper function arguments aligning * when SSE code is used. Some systems (Windows, QNX) do not guarantee our diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c index 3ec857ca..5d110500 100644 --- a/OpenAL32/alAuxEffectSlot.c +++ b/OpenAL32/alAuxEffectSlot.c @@ -118,9 +118,7 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo ALsizei newcount = curarray->count + n; ALCdevice *device; - newarray = al_calloc(DEF_ALIGN, - offsetof(struct ALeffectslotArray, slot[newcount]) - ); + newarray = al_calloc(DEF_ALIGN, FAM_SIZE(struct ALeffectslotArray, slot, newcount)); newarray->count = newcount; memcpy(newarray->slot, tmpslots, sizeof(ALeffectslot*)*n); if(curarray) @@ -170,9 +168,7 @@ AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint * ALsizei j, k; assert(newcount >= 0); - newarray = al_calloc(DEF_ALIGN, - offsetof(struct ALeffectslotArray, slot[newcount]) - ); + newarray = al_calloc(DEF_ALIGN, FAM_SIZE(struct ALeffectslotArray, slot, newcount)); newarray->count = newcount; for(i = j = 0;i < newarray->count;) { diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index 236188cf..9fc22205 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -3013,7 +3013,7 @@ static void UpdateSourceProps(ALsource *source, ALvoice *voice, ALsizei num_send /* Get an unused property container, or allocate a new one as needed. */ props = ATOMIC_LOAD(&voice->FreeList, almemory_order_acquire); if(!props) - props = al_calloc(16, offsetof(struct ALvoiceProps, Send[num_sends])); + props = al_calloc(16, FAM_SIZE(struct ALvoiceProps, Send, num_sends)); else { struct ALvoiceProps *next; |