aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/helpers.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-11-26 03:52:07 -0800
committerChris Robinson <[email protected]>2011-11-26 03:52:07 -0800
commit222d2363cdcbe563eb0a96b2b9c032ade062762f (patch)
tree880008590767bebb24b740ef275f188ec66b3e10 /Alc/helpers.c
parent14c117ffd3d8276b56c676b6bfa8de7b3ef9fce0 (diff)
Don't fail to insert a map entry when the key exists and the limit is reached
Diffstat (limited to 'Alc/helpers.c')
-rw-r--r--Alc/helpers.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/Alc/helpers.c b/Alc/helpers.c
index f219f4ae..c5e2be6c 100644
--- a/Alc/helpers.c
+++ b/Alc/helpers.c
@@ -337,12 +337,6 @@ ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value)
ALsizei pos = 0;
WriteLock(&map->lock);
- if(map->size == map->limit)
- {
- WriteUnlock(&map->lock);
- return AL_OUT_OF_MEMORY;
- }
-
if(map->size > 0)
{
ALsizei low = 0;
@@ -362,6 +356,12 @@ ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value)
if(pos == map->size || map->array[pos].key != key)
{
+ if(map->size == map->limit)
+ {
+ WriteUnlock(&map->lock);
+ return AL_OUT_OF_MEMORY;
+ }
+
if(map->size == map->maxsize)
{
ALvoid *temp = NULL;
@@ -379,10 +379,10 @@ ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value)
map->maxsize = newsize;
}
- map->size++;
- if(pos < map->size-1)
+ if(pos < map->size)
memmove(&map->array[pos+1], &map->array[pos],
- (map->size-1-pos)*sizeof(map->array[0]));
+ (map->size-pos)*sizeof(map->array[0]));
+ map->size++;
}
map->array[pos].key = key;
map->array[pos].value = value;