Index: src/runtime/autorelease.m ================================================================== --- src/runtime/autorelease.m +++ src/runtime/autorelease.m @@ -49,13 +49,13 @@ #endif #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OF_CONSTRUCTOR() { - OFEnsure(OFTLSKeyNew(&objectsKey) == 0); - OFEnsure(OFTLSKeyNew(&countKey) == 0); - OFEnsure(OFTLSKeyNew(&sizeKey) == 0); + if (OFTLSKeyNew(&objectsKey) != 0 || OFTLSKeyNew(&countKey) != 0 || + OFTLSKeyNew(&sizeKey) != 0) + OBJC_ERROR("Failed to create TLS keys!"); } #endif void * objc_autoreleasePoolPush() @@ -96,17 +96,19 @@ free(objects); objects = NULL; #if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS) size = 0; #else - OFEnsure(OFTLSKeySet(objectsKey, objects) == 0); - OFEnsure(OFTLSKeySet(sizeKey, (void *)0) == 0); + if (OFTLSKeySet(objectsKey, objects) != 0 || + OFTLSKeySet(sizeKey, (void *)0) != 0) + OBJC_ERROR("Failed to set TLS key!"); #endif } #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) - OFEnsure(OFTLSKeySet(countKey, (void *)count) == 0); + if (OFTLSKeySet(countKey, (void *)count) != 0) + OBJC_ERROR("Failed to set TLS key!"); #endif } id _objc_rootAutorelease(id object) @@ -121,22 +123,24 @@ if (size == 0) size = 16; else size *= 2; - OFEnsure((objects = - realloc(objects, size * sizeof(id))) != NULL); + if ((objects = realloc(objects, size * sizeof(id))) == NULL) + OBJC_ERROR("Failed to resize autorelease pool!"); #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) - OFEnsure(OFTLSKeySet(objectsKey, objects) == 0); - OFEnsure(OFTLSKeySet(sizeKey, (void *)size) == 0); + if (OFTLSKeySet(objectsKey, objects) != 0 || + OFTLSKeySet(sizeKey, (void *)size) != 0) + OBJC_ERROR("Failed to set TLS key!"); #endif } objects[count++] = object; #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) - OFEnsure(OFTLSKeySet(countKey, (void *)count) == 0); + if (OFTLSKeySet(countKey, (void *)count) != 0) + OBJC_ERROR("Failed to set TLS key!"); #endif return object; } Index: src/runtime/class.m ================================================================== --- src/runtime/class.m +++ src/runtime/class.m @@ -472,13 +472,10 @@ objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes) { struct objc_class *class, *metaclass; Class iter, rootclass = Nil; - if (extraBytes > LONG_MAX) - OBJC_ERROR("extraBytes out of range!"); - if ((class = calloc(1, sizeof(*class))) == NULL || (metaclass = calloc(1, sizeof(*class))) == NULL) OBJC_ERROR("Not enough memory to allocate class pair for class " "%s!", name); @@ -485,11 +482,17 @@ class->isa = metaclass; class->superclass = superclass; class->name = name; class->info = OBJC_CLASS_INFO_CLASS; class->instanceSize = (superclass != Nil ? - superclass->instanceSize : 0) + (long)extraBytes; + superclass->instanceSize : 0); + + if (extraBytes > LONG_MAX || + LONG_MAX - class->instanceSize < (long)extraBytes) + OBJC_ERROR("extraBytes too large!"); + + class->instanceSize += (long)extraBytes; for (iter = superclass; iter != Nil; iter = iter->superclass) rootclass = iter; metaclass->isa = (rootclass != Nil ? rootclass->isa : class); @@ -629,11 +632,12 @@ if ((ret = malloc((classesCount + 1) * sizeof(Class))) == NULL) OBJC_ERROR("Failed to allocate memory for class list!"); count = objc_getClassList(ret, classesCount); - OFEnsure(count == classesCount); + if (count != classesCount) + OBJC_ERROR("Fatal internal inconsistency!"); ret[count] = Nil; if (length != NULL) *length = count; @@ -978,11 +982,12 @@ */ i = UINT32_MAX; } } - OFEnsure(classesCount == 0); + if (classesCount != 0) + OBJC_ERROR("Fatal internal inconsistency!"); if (emptyDTable != NULL) { objc_dtable_free(emptyDTable); emptyDTable = NULL; } Index: src/runtime/exception.m ================================================================== --- src/runtime/exception.m +++ src/runtime/exception.m @@ -251,11 +251,11 @@ static OFSpinlock emergencyExceptionsSpinlock; OF_CONSTRUCTOR() { if (OFSpinlockNew(&emergencyExceptionsSpinlock) != 0) - OBJC_ERROR("Cannot create spinlock!"); + OBJC_ERROR("Failed to create spinlock!"); } #endif static uint64_t readULEB128(const uint8_t **ptr) @@ -716,18 +716,18 @@ emergencyExceptionCleanup(_Unwind_Reason_Code reason, struct _Unwind_Exception *ex) { #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&emergencyExceptionsSpinlock) != 0) - OBJC_ERROR("Cannot lock spinlock!"); + OBJC_ERROR("Failed to lock spinlock!"); #endif ex->class = 0; #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&emergencyExceptionsSpinlock) != 0) - OBJC_ERROR("Cannot unlock spinlock!"); + OBJC_ERROR("Failed to unlock spinlock!"); #endif } void objc_exception_throw(id object) @@ -736,11 +736,11 @@ bool emergency = false; if (e == NULL) { #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&emergencyExceptionsSpinlock) != 0) - OBJC_ERROR("Cannot lock spinlock!"); + OBJC_ERROR("Failed to lock spinlock!"); #endif for (uint_fast8_t i = 0; i < numEmergencyExceptions; i++) { if (emergencyExceptions[i].exception.class == 0) { e = &emergencyExceptions[i]; @@ -751,11 +751,11 @@ } } #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&emergencyExceptionsSpinlock) != 0) - OBJC_ERROR("Cannot lock spinlock!"); + OBJC_ERROR("Failed to lock spinlock!"); #endif } if (e == NULL) OBJC_ERROR("Not enough memory to allocate exception!"); Index: src/runtime/hashtable.m ================================================================== --- src/runtime/hashtable.m +++ src/runtime/hashtable.m @@ -117,11 +117,11 @@ for (j = 0; j < last && newData[j] != NULL; j++); } if (j >= last) - OBJC_ERROR("No free bucket!"); + OBJC_ERROR("No free bucket in hash table!"); newData[j] = table->data[i]; } } @@ -189,11 +189,11 @@ for (i = 0; i < last && table->data[i] != NULL && table->data[i] != &objc_deletedBucket; i++); } if (i >= last) - OBJC_ERROR("No free bucket!"); + OBJC_ERROR("No free bucket in hash table!"); if ((bucket = malloc(sizeof(*bucket))) == NULL) OBJC_ERROR("Not enough memory to allocate hash table bucket!"); bucket->key = key; Index: src/runtime/ivar.m ================================================================== --- src/runtime/ivar.m +++ src/runtime/ivar.m @@ -42,11 +42,11 @@ objc_globalMutex_unlock(); return NULL; } if ((ivars = malloc((count + 1) * sizeof(Ivar))) == NULL) - OBJC_ERROR("Not enough memory to copy ivars"); + OBJC_ERROR("Not enough memory to copy ivars!"); for (unsigned int i = 0; i < count; i++) ivars[i] = &class->ivars->ivars[i]; ivars[count] = NULL; Index: src/runtime/lookup.m ================================================================== --- src/runtime/lookup.m +++ src/runtime/lookup.m @@ -42,12 +42,13 @@ ? (Class)object : object_getClass(object)); objc_initializeClass(class); if (!(class->info & OBJC_CLASS_INFO_SETUP)) - OBJC_ERROR("Could not dispatch message for incomplete " - "class %s!", class_getName(class)); + OBJC_ERROR("Could not dispatch message %s for " + "incomplete class %s!", + sel_getName(selector), class_getName(class)); /* * We don't need to handle the case that super was called. * The reason for this is that a call to super is not possible * before a message to the class has been sent and it thus has Index: src/runtime/method.m ================================================================== --- src/runtime/method.m +++ src/runtime/method.m @@ -51,11 +51,14 @@ i = 0; for (iter = class->methodList; iter != NULL; iter = iter->next) for (unsigned int j = 0; j < iter->count; j++) methods[i++] = &iter->methods[j]; - OFEnsure(i == count); + + if (i != count) + OBJC_ERROR("Fatal internal inconsistency!"); + methods[count] = NULL; if (outCount != NULL) *outCount = count; Index: src/runtime/property.m ================================================================== --- src/runtime/property.m +++ src/runtime/property.m @@ -35,11 +35,11 @@ #ifdef OF_HAVE_THREADS OF_CONSTRUCTOR() { for (size_t i = 0; i < numSpinlocks; i++) if (OFSpinlockNew(&spinlocks[i]) != 0) - OBJC_ERROR("Failed to initialize spinlocks!"); + OBJC_ERROR("Failed to create spinlocks!"); } #endif id objc_getProperty(id self, SEL _cmd, ptrdiff_t offset, bool atomic) @@ -47,15 +47,17 @@ if (atomic) { id *ptr = (id *)(void *)((char *)self + offset); #ifdef OF_HAVE_THREADS size_t slot = spinlockSlot(ptr); - OFEnsure(OFSpinlockLock(&spinlocks[slot]) == 0); + if (OFSpinlockLock(&spinlocks[slot]) != 0) + OBJC_ERROR("Failed to lock spinlock!"); @try { return [[*ptr retain] autorelease]; } @finally { - OFEnsure(OFSpinlockUnlock(&spinlocks[slot]) == 0); + if (OFSpinlockUnlock(&spinlocks[slot]) != 0) + OBJC_ERROR("Failed to unlock spinlock!"); } #else return [[*ptr retain] autorelease]; #endif } @@ -70,11 +72,12 @@ if (atomic) { id *ptr = (id *)(void *)((char *)self + offset); #ifdef OF_HAVE_THREADS size_t slot = spinlockSlot(ptr); - OFEnsure(OFSpinlockLock(&spinlocks[slot]) == 0); + if (OFSpinlockLock(&spinlocks[slot]) != 0) + OBJC_ERROR("Failed to lock spinlock!"); @try { #endif id old = *ptr; switch (copy) { @@ -89,11 +92,12 @@ } [old release]; #ifdef OF_HAVE_THREADS } @finally { - OFEnsure(OFSpinlockUnlock(&spinlocks[slot]) == 0); + if (OFSpinlockUnlock(&spinlocks[slot]) != 0) + OBJC_ERROR("Failed to unlock spinlock!"); } #endif return; } @@ -122,15 +126,17 @@ { if (atomic) { #ifdef OF_HAVE_THREADS size_t slot = spinlockSlot(src); - OFEnsure(OFSpinlockLock(&spinlocks[slot]) == 0); + if (OFSpinlockLock(&spinlocks[slot]) != 0) + OBJC_ERROR("Failed to lock spinlock!"); #endif memcpy(dest, src, size); #ifdef OF_HAVE_THREADS - OFEnsure(OFSpinlockUnlock(&spinlocks[slot]) == 0); + if (OFSpinlockUnlock(&spinlocks[slot]) != 0) + OBJC_ERROR("Failed to unlock spinlock!"); #endif return; } @@ -143,15 +149,17 @@ { if (atomic) { #ifdef OF_HAVE_THREADS size_t slot = spinlockSlot(src); - OFEnsure(OFSpinlockLock(&spinlocks[slot]) == 0); + if (OFSpinlockLock(&spinlocks[slot]) != 0) + OBJC_ERROR("Failed to lock spinlock!"); #endif memcpy(dest, src, size); #ifdef OF_HAVE_THREADS - OFEnsure(OFSpinlockUnlock(&spinlocks[slot]) == 0); + if (OFSpinlockUnlock(&spinlocks[slot]) != 0) + OBJC_ERROR("Failed to unlock spinlock!"); #endif return; } @@ -194,11 +202,14 @@ i = 0; for (iter = class->propertyList; iter != NULL; iter = iter->next) for (unsigned int j = 0; j < iter->count; j++) properties[i++] = &iter->properties[j]; - OFEnsure(i == count); + + if (i != count) + OBJC_ERROR("Fatal internal inconsistency!"); + properties[count] = NULL; if (outCount != NULL) *outCount = count; @@ -256,9 +267,9 @@ #undef BOOL_CASE } if (nullIsError && ret == NULL) OBJC_ERROR("Not enough memory to copy property attribute " - "value"); + "value!"); return ret; } Index: src/runtime/selector.m ================================================================== --- src/runtime/selector.m +++ src/runtime/selector.m @@ -78,14 +78,12 @@ (selector = objc_hashtable_get(selectors, name)) != NULL) { objc_globalMutex_unlock(); return (SEL)selector; } - if ((selector = malloc(sizeof(*selector))) == NULL) - OBJC_ERROR("Not enough memory to allocate selector!"); - - if ((selector->UID = (uintptr_t)objc_strdup(name)) == 0) + if ((selector = malloc(sizeof(*selector))) == NULL || + (selector->UID = (uintptr_t)objc_strdup(name)) == 0) OBJC_ERROR("Not enough memory to allocate selector!"); selector->typeEncoding = NULL; if ((freeList = realloc(freeList, Index: src/runtime/sparsearray.m ================================================================== --- src/runtime/sparsearray.m +++ src/runtime/sparsearray.m @@ -24,14 +24,12 @@ struct objc_sparsearray * objc_sparsearray_new(uint8_t levels) { struct objc_sparsearray *sparsearray; - if ((sparsearray = calloc(1, sizeof(*sparsearray))) == NULL) - OBJC_ERROR("Failed to allocate memory for sparse array!"); - - if ((sparsearray->data = calloc(1, sizeof(*sparsearray->data))) == NULL) + if ((sparsearray = calloc(1, sizeof(*sparsearray))) == NULL || + (sparsearray->data = calloc(1, sizeof(*sparsearray->data))) == NULL) OBJC_ERROR("Failed to allocate memory for sparse array!"); sparsearray->levels = levels; return sparsearray; Index: src/runtime/synchronized.m ================================================================== --- src/runtime/synchronized.m +++ src/runtime/synchronized.m @@ -128,10 +128,10 @@ OBJC_ERROR("Failed to unlock mutex!"); return 0; } - OBJC_ERROR("objc_sync_exit() was called for an object not locked!"); + OBJC_ERROR("objc_sync_exit() was called for an unlocked object!"); #else return 0; #endif }