Index: src/OFHTTPServer.m ================================================================== --- src/OFHTTPServer.m +++ src/OFHTTPServer.m @@ -117,18 +117,14 @@ #endif static OF_INLINE OFString * normalizedKey(OFString *key) { - char *cString = OFStrdup(key.UTF8String); + char *cString = OFStrDup(key.UTF8String); unsigned char *tmp = (unsigned char *)cString; bool firstLetter = true; - if (cString == NULL) - @throw [OFOutOfMemoryException - exceptionWithRequestedSize: strlen(key.UTF8String)]; - while (*tmp != '\0') { if (!OFASCIIIsAlpha(*tmp)) { firstLetter = true; tmp++; continue; Index: src/OFLocale.m ================================================================== --- src/OFLocale.m +++ src/OFLocale.m @@ -40,12 +40,11 @@ #ifndef OF_AMIGAOS static void parseLocale(char *locale, OFStringEncoding *encoding, OFString **language, OFString **territory) { - if ((locale = OFStrdup(locale)) == NULL) - return; + locale = OFStrDup(locale); @try { OFStringEncoding enc = OFStringEncodingASCII; char *tmp; Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -1289,10 +1289,11 @@ * @param encoding The encoding for which to return the name * @return The name of the specified OFStringEncoding */ extern OFString *_Nullable OFStringEncodingName(OFStringEncoding encoding); +extern char *_Nullable OFStrDup(const char *_Nonnull); extern size_t OFUTF8StringEncode(OFUnichar, char *); extern ssize_t OFUTF8StringDecode(const char *, size_t, OFUnichar *); extern size_t OFUTF16StringLength(const OFChar16 *); extern size_t OFUTF32StringLength(const OFChar32 *); #ifdef __cplusplus Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -335,10 +335,20 @@ while (*string++ != 0) length++; return length; } + +char * +OFStrDup(const char *string) +{ + size_t length = strlen(string); + char *copy = (char *)OFAllocMemory(1, length + 1); + memcpy(copy, string, length + 1); + + return copy; +} #ifdef OF_HAVE_UNICODE_TABLES static OFString * decomposedString(OFString *self, const char *const *const *table, size_t size) { Index: src/OFURL.m ================================================================== --- src/OFURL.m +++ src/OFURL.m @@ -440,16 +440,11 @@ @try { void *pool = objc_autoreleasePoolPush(); char *tmp, *tmp2; bool isIPv6Host = false; - if ((UTF8String2 = OFStrdup(string.UTF8String)) == NULL) - @throw [OFOutOfMemoryException - exceptionWithRequestedSize: - string.UTF8StringLength]; - - UTF8String = UTF8String2; + UTF8String = UTF8String2 = OFStrDup(string.UTF8String); if ((tmp = strchr(UTF8String, ':')) == NULL) @throw [OFInvalidFormatException exception]; if (strncmp(tmp, "://", 3) != 0) @@ -631,16 +626,11 @@ _URLEncodedHost = [URL->_URLEncodedHost copy]; _port = [URL->_port copy]; _URLEncodedUser = [URL->_URLEncodedUser copy]; _URLEncodedPassword = [URL->_URLEncodedPassword copy]; - if ((UTF8String2 = OFStrdup(string.UTF8String)) == NULL) - @throw [OFOutOfMemoryException - exceptionWithRequestedSize: - string.UTF8StringLength]; - - UTF8String = UTF8String2; + UTF8String = UTF8String2 = OFStrDup(string.UTF8String); if ((tmp = strchr(UTF8String, '#')) != NULL) { *tmp = '\0'; _URLEncodedFragment = [[OFString alloc] initWithUTF8String: tmp + 1]; Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -696,24 +696,10 @@ OFBitsetClear(unsigned char *_Nonnull storage, size_t idx) { storage[idx / CHAR_BIT] &= ~(1u << (idx % CHAR_BIT)); } -static OF_INLINE char *_Nullable -OFStrdup(const char *_Nonnull string) -{ - char *copy; - size_t length = strlen(string); - - if ((copy = (char *)malloc(length + 1)) == NULL) - return NULL; - - memcpy(copy, string, length + 1); - - return copy; -} - static OF_INLINE void OFZeroMemory(void *_Nonnull buffer_, size_t length) { volatile unsigned char *buffer = (volatile unsigned char *)buffer_; Index: src/runtime/misc.m ================================================================== --- src/runtime/misc.m +++ src/runtime/misc.m @@ -129,5 +129,19 @@ abort(); #endif OF_UNREACHABLE } + +static char * +objc_strdup(const char *string) +{ + char *copy; + size_t length = strlen(string); + + if ((copy = (char *)malloc(length + 1)) == NULL) + return NULL; + + memcpy(copy, string, length + 1); + + return copy; +} Index: src/runtime/private.h ================================================================== --- src/runtime/private.h +++ src/runtime/private.h @@ -330,10 +330,11 @@ #else # define objc_global_mutex_lock() # define objc_global_mutex_unlock() # define objc_global_mutex_free() #endif +extern char *_Nullable objc_strdup(const char *_Nonnull string); static inline IMP _Nullable objc_dtable_get(const struct objc_dtable *_Nonnull dtable, uint32_t idx) { #ifdef OF_SELUID24 Index: src/runtime/property.m ================================================================== --- src/runtime/property.m +++ src/runtime/property.m @@ -217,22 +217,22 @@ if (strlen(name) != 1) return NULL; switch (*name) { case 'T': - ret = OFStrdup(property->getter.typeEncoding); + ret = objc_strdup(property->getter.typeEncoding); nullIsError = true; break; case 'G': if (property->attributes & OBJC_PROPERTY_GETTER) { - ret = OFStrdup(property->getter.name); + ret = objc_strdup(property->getter.name); nullIsError = true; } break; case 'S': if (property->attributes & OBJC_PROPERTY_SETTER) { - ret = OFStrdup(property->setter.name); + ret = objc_strdup(property->setter.name); nullIsError = true; } break; #define BOOL_CASE(name, field, flag) \ case name: \ Index: src/runtime/selector.m ================================================================== --- src/runtime/selector.m +++ src/runtime/selector.m @@ -81,11 +81,11 @@ } if ((selector = malloc(sizeof(*selector))) == NULL) OBJC_ERROR("Not enough memory to allocate selector!"); - if ((selector->UID = (uintptr_t)OFStrdup(name)) == 0) + if ((selector->UID = (uintptr_t)objc_strdup(name)) == 0) OBJC_ERROR("Not enough memory to allocate selector!"); selector->typeEncoding = NULL; if ((freeList = realloc(freeList,