Index: src/runtime/class.m ================================================================== --- src/runtime/class.m +++ src/runtime/class.m @@ -906,12 +906,16 @@ objc_unregister_class(cls); /* * The table might have been resized, so go back to the * start again. + * + * Due to the i++ in the for loop, we need to set it to + * UINT_FAST32_MAX so that it will get increased at the + * end of the loop and thus become 0. */ - i = 0; + i = UINT_FAST32_MAX; } } assert(classes_cnt == 0); Index: src/runtime/hashtable.m ================================================================== --- src/runtime/hashtable.m +++ src/runtime/hashtable.m @@ -85,21 +85,23 @@ fullness = count * 8 / table->size; if (fullness >= 6) { if (table->size > UINT32_MAX / 2) - nsize = table->size; + return; nsize = table->size * 2; } else if (fullness <= 1) nsize = table->size / 2; else return; - if ((ndata = calloc(nsize, - sizeof(struct objc_hashtable_bucket*))) == NULL) - OBJC_ERROR("Not enough memory to insert into hash table!"); + if (count < table->count && nsize < 16) + return; + + if ((ndata = calloc(nsize, sizeof(sizeof(*ndata)))) == NULL) + OBJC_ERROR("Not enough memory to resize hash table!"); for (i = 0; i < table->size; i++) { if (table->data[i] != NULL && table->data[i] != &objc_deleted_bucket) { uint32_t j, last; @@ -188,11 +190,11 @@ } if (i >= last) OBJC_ERROR("No free bucket!"); - if ((bucket = malloc(sizeof(struct objc_hashtable_bucket))) == NULL) + if ((bucket = malloc(sizeof(*bucket))) == NULL) OBJC_ERROR("Not enough memory to allocate hash table bucket!"); bucket->key = key; bucket->hash = hash; bucket->obj = obj;