Index: src/OFMutableDictionary.m ================================================================== --- src/OFMutableDictionary.m +++ src/OFMutableDictionary.m @@ -18,26 +18,24 @@ #import "OFMacros.h" #define BUCKET_SIZE sizeof(struct of_dictionary_bucket) static OF_INLINE void -resize(id self, size_t count, struct of_dictionary_bucket **data, size_t *size) +resize(id self, Class isa, size_t count, struct of_dictionary_bucket **data, + size_t *size) { float fill = (float)count / *size; size_t newsize; struct of_dictionary_bucket *newdata; uint32_t i; - /* - * FIXME: - * - * Throw an OFOutOfRangeException if it would overflow (unlikely to - * happen). - */ - if (fill > 0.75) + if (fill > 0.75) { + if (*size > SIZE_MAX / 2) + @throw [OFOutOfRangeException newWithClass: isa]; + newsize = *size * 2; - else if (fill < 0.25) + } else if (fill < 0.25) newsize = *size / 2; else return; newdata = [self allocMemoryForNItems: newsize @@ -88,11 +86,11 @@ for (i = 0; i < size && data[i].key != nil && ![data[i].key isEqual: key]; i++); /* Key not in dictionary */ if (i >= size || data[i].key == nil) { - resize(self, count + 1, &data, &size); + resize(self, isa, count + 1, &data, &size); i = hash & (size - 1); for (; i < size && data[i].key != nil; i++); /* In case the last bucket is already used */ @@ -141,15 +139,15 @@ [data[i].key release]; [data[i].object release]; data[i].key = nil; count--; - resize(self, count, &data, &size); + resize(self, isa, count, &data, &size); return self; } - (id)copy { return [[OFDictionary alloc] initWithDictionary: self]; } @end