Index: src/OFDictionary.h ================================================================== --- src/OFDictionary.h +++ src/OFDictionary.h @@ -18,12 +18,12 @@ /// \cond internal struct of_dictionary_bucket { OFObject *key; - OFObject *object; - uint32_t hash; + OFObject *object; + uint32_t hash; }; /// \endcond /** * \brief A class for storing objects in a hash table. @@ -30,12 +30,12 @@ */ @interface OFDictionary: OFObject { struct of_dictionary_bucket *data; - size_t size; - size_t count; + uint32_t size; + size_t count; } /** * Creates a new OFDictionary. * @@ -161,18 +161,18 @@ /// \cond internal @interface OFDictionaryEnumerator: OFEnumerator { struct of_dictionary_bucket *data; - size_t size; - unsigned long mutations; - unsigned long *mutations_ptr; - size_t pos; + uint32_t size; + unsigned long mutations; + unsigned long *mutations_ptr; + uint32_t pos; } - initWithData: (struct of_dictionary_bucket*)data - size: (size_t)size + size: (uint32_t)size mutationsPointer: (unsigned long*)mutations_ptr; @end @interface OFDictionaryObjectEnumerator: OFDictionaryEnumerator @end Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -85,11 +85,11 @@ return self; } - initWithDictionary: (OFDictionary*)dict { - size_t i; + uint32_t i; self = [super init]; if (dict == nil) { Class c = isa; @@ -204,15 +204,18 @@ @try { keys_carray = [keys cArray]; objs_carray = [objs cArray]; count = [keys count]; - if (count > SIZE_MAX / 8) + if (count > UINT32_MAX) @throw [OFOutOfRangeException newWithClass: isa]; for (size = 1; size < count; size <<= 1); + if (size == 0) + @throw [OFOutOfRangeException newWithClass: isa]; + data = [self allocMemoryForNItems: size withSize: BUCKET_SIZE]; } @catch (OFException *e) { /* * We can't use [super dealloc] on OS X here. Compiler bug? @@ -337,17 +340,23 @@ count = 1; for (va_copy(args2, args); va_arg(args2, OFObject*) != nil; count++); count >>= 1; - if (count > SIZE_MAX / 8) { + if (count > UINT32_MAX) { Class c = isa; [self dealloc]; @throw [OFOutOfRangeException newWithClass: c]; } for (size = 1; size < count; size <<= 1); + + if (size == 0) { + Class c = isa; + [self dealloc]; + @throw [OFOutOfRangeException newWithClass: c]; + } @try { data = [self allocMemoryForNItems: size withSize: BUCKET_SIZE]; } @catch (OFException *e) { @@ -393,11 +402,11 @@ data[j].key = key; data[j].object = obj; data[j].hash = hash; for (i = 1; i < count; i++) { - size_t last; + uint32_t last; key = va_arg(args, OFObject *); obj = va_arg(args, OFObject*); if (key == nil || obj == nil) { @@ -539,11 +548,11 @@ return [[OFMutableDictionary alloc] initWithDictionary: self]; } - (BOOL)isEqual: (OFDictionary*)dict { - size_t i; + uint32_t i; if ([dict count] != count) return NO; for (i = 0; i < size; i++) @@ -556,11 +565,11 @@ - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects count: (int)count_ { - size_t i; + int i; for (i = 0; i < count_; i++) { for (; state->state < size && (data[state->state].key == nil || data[state->state].key == DELETED); state->state++); @@ -593,11 +602,11 @@ mutationsPointer: NULL] autorelease]; } - (void)dealloc { - size_t i; + uint32_t i; for (i = 0; i < size; i++) { if (data[i].key != nil && data[i].key != DELETED) { [data[i].key release]; [data[i].object release]; @@ -607,11 +616,11 @@ [super dealloc]; } - (uint32_t)hash { - size_t i; + uint32_t i; uint32_t hash; OF_HASH_INIT(hash); for (i = 0; i < size; i++) { @@ -637,11 +646,11 @@ @end /// \cond internal @implementation OFDictionaryEnumerator - initWithData: (struct of_dictionary_bucket*)data_ - size: (size_t)size_ + size: (uint32_t)size_ mutationsPointer: (unsigned long*)mutations_ptr_ { self = [super init]; data = data_; Index: src/OFMutableDictionary.m ================================================================== --- src/OFMutableDictionary.m +++ src/OFMutableDictionary.m @@ -26,11 +26,11 @@ size_t fill = newcount * 4 / size; size_t newsize; struct of_dictionary_bucket *newdata; uint32_t i; - if (newcount > SIZE_MAX / 4) + if (newcount > UINT32_MAX) @throw [OFOutOfRangeException newWithClass: isa]; if (fill >= 3) newsize = size << 1; else if (fill <= 1) @@ -198,11 +198,11 @@ - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects count: (int)count_ { - size_t i; + int i; for (i = 0; i < count_; i++) { for (; state->state < size && (data[state->state].key == nil || data[state->state].key == DELETED); state->state++);