diff options
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/alAuxEffectSlot.c | 90 | ||||
-rw-r--r-- | OpenAL32/alBuffer.c | 49 | ||||
-rw-r--r-- | OpenAL32/alDatabuffer.c | 58 | ||||
-rw-r--r-- | OpenAL32/alEffect.c | 52 | ||||
-rw-r--r-- | OpenAL32/alFilter.c | 52 | ||||
-rw-r--r-- | OpenAL32/alSource.c | 74 |
6 files changed, 166 insertions, 209 deletions
diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c index 9c5cf5fc..dfc0ad18 100644 --- a/OpenAL32/alAuxEffectSlot.c +++ b/OpenAL32/alAuxEffectSlot.c @@ -40,67 +40,61 @@ static ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, AL AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots) { ALCcontext *Context; - ALsizei i=0, j; + ALCdevice *Device; Context = GetContextSuspended(); if(!Context) return; - if(n < 0) + Device = Context->Device; + if(n < 0 || IsBadWritePtr((void*)effectslots, n * sizeof(ALuint))) + alSetError(Context, AL_INVALID_VALUE); + else if((ALuint)n > Device->AuxiliaryEffectSlotMax - Context->EffectSlotMap.size) alSetError(Context, AL_INVALID_VALUE); else { - ALCdevice *Device = Context->Device; + ALenum err; + ALsizei i, j; - if((ALuint)n <= Device->AuxiliaryEffectSlotMax - Context->EffectSlotMap.size) + i = 0; + while(i < n) { - // Check that enough memory has been allocted in the 'effectslots' array for n Effect Slots - if(!IsBadWritePtr((void*)effectslots, n * sizeof(ALuint))) + ALeffectslot *slot = calloc(1, sizeof(ALeffectslot)); + if(!slot || !(slot->EffectState=NoneCreate())) { - ALenum err; + free(slot); + // We must have run out or memory + alSetError(Context, AL_OUT_OF_MEMORY); + alDeleteAuxiliaryEffectSlots(i, effectslots); + break; + } - while(i < n) - { - ALeffectslot *slot = calloc(1, sizeof(ALeffectslot)); - if(!slot || !(slot->EffectState=NoneCreate())) - { - free(slot); - // We must have run out or memory - alSetError(Context, AL_OUT_OF_MEMORY); - alDeleteAuxiliaryEffectSlots(i, effectslots); - break; - } - - slot->effectslot = (ALuint)ALTHUNK_ADDENTRY(slot); - err = InsertUIntMapEntry(&Context->EffectSlotMap, - slot->effectslot, slot); - if(err != AL_NO_ERROR) - { - ALTHUNK_REMOVEENTRY(slot->effectslot); - ALEffect_Destroy(slot->EffectState); - free(slot); - - alSetError(Context, err); - alDeleteAuxiliaryEffectSlots(i, effectslots); - break; - } - - effectslots[i++] = slot->effectslot; - - slot->Gain = 1.0; - slot->AuxSendAuto = AL_TRUE; - for(j = 0;j < BUFFERSIZE;j++) - slot->WetBuffer[j] = 0.0f; - for(j = 0;j < 1;j++) - { - slot->ClickRemoval[j] = 0.0f; - slot->PendingClicks[j] = 0.0f; - } - slot->refcount = 0; - } + slot->effectslot = (ALuint)ALTHUNK_ADDENTRY(slot); + err = InsertUIntMapEntry(&Context->EffectSlotMap, + slot->effectslot, slot); + if(err != AL_NO_ERROR) + { + ALTHUNK_REMOVEENTRY(slot->effectslot); + ALEffect_Destroy(slot->EffectState); + free(slot); + + alSetError(Context, err); + alDeleteAuxiliaryEffectSlots(i, effectslots); + break; + } + + effectslots[i++] = slot->effectslot; + + slot->Gain = 1.0; + slot->AuxSendAuto = AL_TRUE; + for(j = 0;j < BUFFERSIZE;j++) + slot->WetBuffer[j] = 0.0f; + for(j = 0;j < 1;j++) + { + slot->ClickRemoval[j] = 0.0f; + slot->PendingClicks[j] = 0.0f; } + slot->refcount = 0; } - else - alSetError(Context, AL_INVALID_OPERATION); } ProcessContext(Context); diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c index 6ea11cdd..f00ac58b 100644 --- a/OpenAL32/alBuffer.c +++ b/OpenAL32/alBuffer.c @@ -114,45 +114,38 @@ AL_API ALvoid AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers) Context = GetContextSuspended(); if(!Context) return; - // Check that we are actually generation some Buffers - if(n < 0) + // Check that we are actually generating some Buffers + if(n < 0 || IsBadWritePtr((void*)buffers, n * sizeof(ALuint))) alSetError(Context, AL_INVALID_VALUE); else { ALCdevice *device = Context->Device; ALenum err; - // Check the pointer is valid (and points to enough memory to store Buffer Names) - if(IsBadWritePtr((void*)buffers, n * sizeof(ALuint))) - alSetError(Context, AL_INVALID_VALUE); - else + // Create all the new Buffers + while(i < n) { - // Create all the new Buffers - while(i < n) + ALbuffer *buffer = calloc(1, sizeof(ALbuffer)); + if(!buffer) { - ALbuffer *buffer = calloc(1, sizeof(ALbuffer)); - if(!buffer) - { - alSetError(Context, AL_OUT_OF_MEMORY); - alDeleteBuffers(i, buffers); - break; - } + alSetError(Context, AL_OUT_OF_MEMORY); + alDeleteBuffers(i, buffers); + break; + } - buffer->buffer = (ALuint)ALTHUNK_ADDENTRY(buffer); - err = InsertUIntMapEntry(&device->BufferMap, buffer->buffer, - buffer); - if(err != AL_NO_ERROR) - { - ALTHUNK_REMOVEENTRY(buffer->buffer); - memset(buffer, 0, sizeof(ALbuffer)); - free(buffer); + buffer->buffer = (ALuint)ALTHUNK_ADDENTRY(buffer); + err = InsertUIntMapEntry(&device->BufferMap, buffer->buffer, buffer); + if(err != AL_NO_ERROR) + { + ALTHUNK_REMOVEENTRY(buffer->buffer); + memset(buffer, 0, sizeof(ALbuffer)); + free(buffer); - alSetError(Context, err); - alDeleteBuffers(i, buffers); - break; - } - buffers[i++] = buffer->buffer; + alSetError(Context, err); + alDeleteBuffers(i, buffers); + break; } + buffers[i++] = buffer->buffer; } } diff --git a/OpenAL32/alDatabuffer.c b/OpenAL32/alDatabuffer.c index b799f133..060aaf0c 100644 --- a/OpenAL32/alDatabuffer.c +++ b/OpenAL32/alDatabuffer.c @@ -48,47 +48,41 @@ AL_API ALvoid AL_APIENTRY alGenDatabuffersEXT(ALsizei n,ALuint *puiBuffers) if(!Context) return; /* Check that we are actually generation some Databuffers */ - if(n > 0) + if(n < 0 || IsBadWritePtr((void*)puiBuffers, n * sizeof(ALuint))) + alSetError(Context, AL_INVALID_VALUE); + else { ALCdevice *device = Context->Device; + ALenum err; - /* Check the pointer is valid (and points to enough memory to store - * Databuffer Names) */ - if(!IsBadWritePtr((void*)puiBuffers, n * sizeof(ALuint))) + /* Create all the new Databuffers */ + while(i < n) { - ALenum err; - - /* Create all the new Databuffers */ - while(i < n) + ALdatabuffer *buffer = calloc(1, sizeof(ALdatabuffer)); + if(!buffer) { - ALdatabuffer *buffer = calloc(1, sizeof(ALdatabuffer)); - if(!buffer) - { - alSetError(Context, AL_OUT_OF_MEMORY); - alDeleteDatabuffersEXT(i, puiBuffers); - break; - } - - buffer->databuffer = ALTHUNK_ADDENTRY(buffer); - err = InsertUIntMapEntry(&device->DatabufferMap, - buffer->databuffer, buffer); - if(err != AL_NO_ERROR) - { - ALTHUNK_REMOVEENTRY(buffer->databuffer); - memset(buffer, 0, sizeof(ALdatabuffer)); - free(buffer); + alSetError(Context, AL_OUT_OF_MEMORY); + alDeleteDatabuffersEXT(i, puiBuffers); + break; + } - alSetError(Context, err); - alDeleteDatabuffersEXT(i, puiBuffers); - break; - } - puiBuffers[i++] = buffer->databuffer; + buffer->databuffer = ALTHUNK_ADDENTRY(buffer); + err = InsertUIntMapEntry(&device->DatabufferMap, + buffer->databuffer, buffer); + if(err != AL_NO_ERROR) + { + ALTHUNK_REMOVEENTRY(buffer->databuffer); + memset(buffer, 0, sizeof(ALdatabuffer)); + free(buffer); - buffer->state = UNMAPPED; + alSetError(Context, err); + alDeleteDatabuffersEXT(i, puiBuffers); + break; } + puiBuffers[i++] = buffer->databuffer; + + buffer->state = UNMAPPED; } - else - alSetError(Context, AL_INVALID_VALUE); } ProcessContext(Context); diff --git a/OpenAL32/alEffect.c b/OpenAL32/alEffect.c index f3109ca2..e1c022a0 100644 --- a/OpenAL32/alEffect.c +++ b/OpenAL32/alEffect.c @@ -46,42 +46,38 @@ AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects) Context = GetContextSuspended(); if(!Context) return; - if (n > 0) + if(n < 0 || IsBadWritePtr((void*)effects, n * sizeof(ALuint))) + alSetError(Context, AL_INVALID_VALUE); + else { ALCdevice *device = Context->Device; + ALenum err; - // Check that enough memory has been allocted in the 'effects' array for n Effects - if (!IsBadWritePtr((void*)effects, n * sizeof(ALuint))) + while(i < n) { - ALenum err; - - while(i < n) + ALeffect *effect = calloc(1, sizeof(ALeffect)); + if(!effect) { - ALeffect *effect = calloc(1, sizeof(ALeffect)); - if(!effect) - { - alSetError(Context, AL_OUT_OF_MEMORY); - alDeleteEffects(i, effects); - break; - } - - effect->effect = ALTHUNK_ADDENTRY(effect); - err = InsertUIntMapEntry(&device->EffectMap, effect->effect, - effect); - if(err != AL_NO_ERROR) - { - ALTHUNK_REMOVEENTRY(effect->effect); - memset(effect, 0, sizeof(ALeffect)); - free(effect); + alSetError(Context, AL_OUT_OF_MEMORY); + alDeleteEffects(i, effects); + break; + } - alSetError(Context, err); - alDeleteEffects(i, effects); - break; - } + effect->effect = ALTHUNK_ADDENTRY(effect); + err = InsertUIntMapEntry(&device->EffectMap, effect->effect, effect); + if(err != AL_NO_ERROR) + { + ALTHUNK_REMOVEENTRY(effect->effect); + memset(effect, 0, sizeof(ALeffect)); + free(effect); - effects[i++] = effect->effect; - InitEffectParams(effect, AL_EFFECT_NULL); + alSetError(Context, err); + alDeleteEffects(i, effects); + break; } + + effects[i++] = effect->effect; + InitEffectParams(effect, AL_EFFECT_NULL); } } diff --git a/OpenAL32/alFilter.c b/OpenAL32/alFilter.c index 35a58c7a..0d66b531 100644 --- a/OpenAL32/alFilter.c +++ b/OpenAL32/alFilter.c @@ -42,42 +42,38 @@ AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) Context = GetContextSuspended(); if(!Context) return; - if (n > 0) + if(n < 0 || IsBadWritePtr((void*)filters, n * sizeof(ALuint))) + alSetError(Context, AL_INVALID_VALUE); + else { ALCdevice *device = Context->Device; + ALenum err; - // Check that enough memory has been allocted in the 'filters' array for n Filters - if (!IsBadWritePtr((void*)filters, n * sizeof(ALuint))) + while(i < n) { - ALenum err; - - while(i < n) + ALfilter *filter = calloc(1, sizeof(ALfilter)); + if(!filter) { - ALfilter *filter = calloc(1, sizeof(ALfilter)); - if(!filter) - { - alSetError(Context, AL_OUT_OF_MEMORY); - alDeleteFilters(i, filters); - break; - } - - filter->filter = ALTHUNK_ADDENTRY(filter); - err = InsertUIntMapEntry(&device->FilterMap, filter->filter, - filter); - if(err != AL_NO_ERROR) - { - ALTHUNK_REMOVEENTRY(filter->filter); - memset(filter, 0, sizeof(ALfilter)); - free(filter); + alSetError(Context, AL_OUT_OF_MEMORY); + alDeleteFilters(i, filters); + break; + } - alSetError(Context, err); - alDeleteFilters(i, filters); - break; - } + filter->filter = ALTHUNK_ADDENTRY(filter); + err = InsertUIntMapEntry(&device->FilterMap, filter->filter, filter); + if(err != AL_NO_ERROR) + { + ALTHUNK_REMOVEENTRY(filter->filter); + memset(filter, 0, sizeof(ALfilter)); + free(filter); - filters[i++] = filter->filter; - InitFilterParams(filter, AL_FILTER_NULL); + alSetError(Context, err); + alDeleteFilters(i, filters); + break; } + + filters[i++] = filter->filter; + InitFilterParams(filter, AL_FILTER_NULL); } } diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index 32e8c4da..a863876e 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -47,64 +47,48 @@ AL_API ALvoid AL_APIENTRY alGenSources(ALsizei n,ALuint *sources) { ALCcontext *Context; ALCdevice *Device; - ALsizei i=0; Context = GetContextSuspended(); if(!Context) return; - if(n < 0) + Device = Context->Device; + if(n < 0 || IsBadWritePtr((void*)sources, n * sizeof(ALuint))) + alSetError(Context, AL_INVALID_VALUE); + else if((ALuint)n > Device->MaxNoOfSources - Context->SourceMap.size) alSetError(Context, AL_INVALID_VALUE); else { - Device = Context->Device; + ALenum err; + ALsizei i; - // Check that enough memory has been allocted in the 'sources' array for n Sources - if(!IsBadWritePtr((void*)sources, n * sizeof(ALuint))) + // Add additional sources to the list + i = 0; + while(i < n) { - // Check that the requested number of sources can be generated - if((ALuint)n <= Device->MaxNoOfSources - Context->SourceMap.size) + ALsource *source = calloc(1, sizeof(ALsource)); + if(!source) { - ALenum err; - - // Add additional sources to the list - while(i < n) - { - ALsource *source = calloc(1, sizeof(ALsource)); - if(!source) - { - alSetError(Context, AL_OUT_OF_MEMORY); - alDeleteSources(i, sources); - break; - } - - source->source = (ALuint)ALTHUNK_ADDENTRY(source); - err = InsertUIntMapEntry(&Context->SourceMap, source->source, - source); - if(err != AL_NO_ERROR) - { - ALTHUNK_REMOVEENTRY(source->source); - memset(source, 0, sizeof(ALsource)); - free(source); - - alSetError(Context, err); - alDeleteSources(i, sources); - break; - } - - sources[i++] = source->source; - InitSourceParams(source); - } + alSetError(Context, AL_OUT_OF_MEMORY); + alDeleteSources(i, sources); + break; } - else + + source->source = (ALuint)ALTHUNK_ADDENTRY(source); + err = InsertUIntMapEntry(&Context->SourceMap, source->source, + source); + if(err != AL_NO_ERROR) { - // Not enough resources to create the Sources - alSetError(Context, AL_INVALID_VALUE); + ALTHUNK_REMOVEENTRY(source->source); + memset(source, 0, sizeof(ALsource)); + free(source); + + alSetError(Context, err); + alDeleteSources(i, sources); + break; } - } - else - { - // Bad pointer - alSetError(Context, AL_INVALID_VALUE); + + sources[i++] = source->source; + InitSourceParams(source); } } |