Reduce some indentation

This commit is contained in:
Chris Robinson 2010-09-21 15:12:08 -07:00
parent 301a8ba3a4
commit 8a1d5a21c3
6 changed files with 175 additions and 218 deletions

View File

@ -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;
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;
}
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;
}
else
alSetError(Context, AL_INVALID_OPERATION);
}
ProcessContext(Context);

View File

@ -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;
}
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, 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);
alSetError(Context, err);
alDeleteBuffers(i, buffers);
break;
}
buffers[i++] = buffer->buffer;
}
}

View File

@ -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, err);
alDeleteDatabuffersEXT(i, puiBuffers);
break;
}
puiBuffers[i++] = buffer->databuffer;
buffer->state = UNMAPPED;
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, err);
alDeleteDatabuffersEXT(i, puiBuffers);
break;
}
puiBuffers[i++] = buffer->databuffer;
buffer->state = UNMAPPED;
}
else
alSetError(Context, AL_INVALID_VALUE);
}
ProcessContext(Context);

View File

@ -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, err);
alDeleteEffects(i, effects);
break;
}
effects[i++] = effect->effect;
InitEffectParams(effect, AL_EFFECT_NULL);
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, err);
alDeleteEffects(i, effects);
break;
}
effects[i++] = effect->effect;
InitEffectParams(effect, AL_EFFECT_NULL);
}
}

View File

@ -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, err);
alDeleteFilters(i, filters);
break;
}
filters[i++] = filter->filter;
InitFilterParams(filter, AL_FILTER_NULL);
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, err);
alDeleteFilters(i, filters);
break;
}
filters[i++] = filter->filter;
InitFilterParams(filter, AL_FILTER_NULL);
}
}

View File

@ -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);
}
}