From 222d2363cdcbe563eb0a96b2b9c032ade062762f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 26 Nov 2011 03:52:07 -0800 Subject: Don't fail to insert a map entry when the key exists and the limit is reached --- Alc/helpers.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'Alc/helpers.c') 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; -- cgit v1.2.3