Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -239,11 +239,11 @@ } - (id const *)objects { size_t count = self.count; - id *buffer = of_malloc(count, sizeof(id)); + id *buffer = of_alloc(count, sizeof(id)); @try { [self getObjects: buffer inRange: of_range(0, count)]; @@ -381,11 +381,11 @@ if (![self isKindOfClass: [OFMutableArray class]]) return [OFSubarray arrayWithArray: self range: range]; - buffer = of_malloc(range.length, sizeof(*buffer)); + buffer = of_alloc(range.length, sizeof(*buffer)); @try { [self getObjects: buffer inRange: range]; ret = [OFArray arrayWithObjects: buffer @@ -856,11 +856,11 @@ #ifdef OF_HAVE_BLOCKS - (OFArray *)mappedArrayUsingBlock: (of_array_map_block_t)block { OFArray *ret; size_t count = self.count; - id *tmp = of_malloc(count, sizeof(id)); + id *tmp = of_alloc(count, sizeof(id)); @try { [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { tmp[idx] = block(object, idx); @@ -877,11 +877,11 @@ - (OFArray *)filteredArrayUsingBlock: (of_array_filter_block_t)block { OFArray *ret; size_t count = self.count; - id *tmp = of_malloc(count, sizeof(id)); + id *tmp = of_alloc(count, sizeof(id)); @try { __block size_t i = 0; [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, Index: src/OFBytesValue.m ================================================================== --- src/OFBytesValue.m +++ src/OFBytesValue.m @@ -29,11 +29,11 @@ self = [super init]; @try { _size = of_sizeof_type_encoding(objCType); _objCType = objCType; - _bytes = of_malloc(1, _size); + _bytes = of_alloc(1, _size); memcpy(_bytes, bytes, _size); } @catch (id e) { [self release]; @throw e; Index: src/OFConstantString.m ================================================================== --- src/OFConstantString.m +++ src/OFConstantString.m @@ -111,11 +111,11 @@ struct of_string_utf8_ivars *ivars; if ([self isMemberOfClass: [OFConstantUTF8String class]]) return; - ivars = of_calloc(1, sizeof(*ivars)); + ivars = of_alloc_zeroed(1, sizeof(*ivars)); ivars->cString = _cString; ivars->cStringLength = _cStringLength; switch (of_string_utf8_check(ivars->cString, ivars->cStringLength, &ivars->length)) { Index: src/OFDNSResolver.m ================================================================== --- src/OFDNSResolver.m +++ src/OFDNSResolver.m @@ -1136,11 +1136,11 @@ context->_responseLength = 0; return nil; } if (context->_TCPBuffer == nil) - context->_TCPBuffer = of_malloc(MAX_DNS_RESPONSE_LENGTH, 1); + context->_TCPBuffer = of_alloc(MAX_DNS_RESPONSE_LENGTH, 1); [sock asyncReadIntoBuffer: context->_TCPBuffer exactLength: 2]; return nil; } Index: src/OFData.m ================================================================== --- src/OFData.m +++ src/OFData.m @@ -131,11 +131,11 @@ @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; - _items = of_malloc(count, itemSize); + _items = of_alloc(count, itemSize); _count = count; _itemSize = itemSize; _freeWhenDone = true; memcpy(_items, items, count * itemSize); @@ -195,11 +195,11 @@ # if ULLONG_MAX > SIZE_MAX if (size > SIZE_MAX) @throw [OFOutOfRangeException exception]; # endif - buffer = of_malloc((size_t)size, 1); + buffer = of_alloc((size_t)size, 1); file = [[OFFile alloc] initWithPath: path mode: @"r"]; @try { [file readIntoBuffer: buffer exactLength: (size_t)size]; @@ -247,11 +247,11 @@ _count = 0; _itemSize = 1; _freeWhenDone = true; pageSize = [OFSystemInfo pageSize]; - buffer = of_malloc(1, pageSize); + buffer = of_alloc(1, pageSize); @try { while (!stream.atEndOfStream) { size_t length = [stream readIntoBuffer: buffer @@ -290,11 +290,11 @@ if (count % 2 != 0) @throw [OFInvalidFormatException exception]; count /= 2; - _items = of_malloc(count, 1); + _items = of_alloc(count, 1); _count = count; _itemSize = 1; _freeWhenDone = true; cString = [string Index: src/OFDate.m ================================================================== --- src/OFDate.m +++ src/OFDate.m @@ -777,11 +777,11 @@ } # endif #endif pageSize = [OFSystemInfo pageSize]; - buffer = of_malloc(1, pageSize); + buffer = of_alloc(1, pageSize); @try { #ifndef OF_WINDOWS if (strftime(buffer, pageSize, format.UTF8String, &tm) == 0) @throw [OFOutOfRangeException exception]; @@ -837,11 +837,11 @@ } # endif #endif pageSize = [OFSystemInfo pageSize]; - buffer = of_malloc(1, pageSize); + buffer = of_alloc(1, pageSize); @try { #ifndef OF_WINDOWS if (strftime(buffer, pageSize, format.UTF8String, &tm) == 0) @throw [OFOutOfRangeException exception]; Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -241,11 +241,11 @@ @throw [OFOpenItemFailedException exceptionWithPath: path mode: mode errNo: errno]; #else - handle = of_malloc(1, sizeof(*handle)); + handle = of_alloc(1, sizeof(*handle)); @try { if ((flags = parseMode(mode.UTF8String, &handle->append)) == -1) @throw [OFInvalidArgumentException exception]; Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -663,11 +663,11 @@ size_t pageSize = [OFSystemInfo pageSize]; OFStream *sourceStream = nil; OFStream *destinationStream = nil; char *buffer; - buffer = of_malloc(1, pageSize); + buffer = of_alloc(1, pageSize); @try { sourceStream = [[OFURLHandler handlerForURL: source] openItemAtURL: source mode: @"r"]; destinationStream = [[OFURLHandler handlerForURL: Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -513,11 +513,11 @@ lineC = line.UTF8String; if ((tmp = strchr(lineC, ':')) == NULL) @throw [OFInvalidServerReplyException exception]; - keyC = of_malloc(tmp - lineC + 1, 1); + keyC = of_alloc(tmp - lineC + 1, 1); memcpy(keyC, lineC, tmp - lineC); keyC[tmp - lineC] = '\0'; normalizeKey(keyC); @try { Index: src/OFInflateStream.m ================================================================== --- src/OFInflateStream.m +++ src/OFInflateStream.m @@ -194,11 +194,11 @@ #ifdef OF_INFLATE64_STREAM_M _slidingWindowMask = 0xFFFF; #else _slidingWindowMask = 0x7FFF; #endif - _slidingWindow = of_calloc(_slidingWindowMask + 1, 1); + _slidingWindow = of_alloc_zeroed(_slidingWindowMask + 1, 1); } @catch (id e) { [self release]; @throw e; } @@ -378,11 +378,11 @@ CTX.codeLenCodesCount = bits; } if OF_LIKELY (CTX.lengths == NULL) - CTX.lengths = of_calloc(19, 1); + CTX.lengths = of_alloc_zeroed(19, 1); for (uint16_t i = CTX.receivedCount; i < CTX.codeLenCodesCount + 4; i++) { if OF_UNLIKELY (!tryReadBits(self, &bits, 3)) { CTX.receivedCount = i; @@ -401,11 +401,11 @@ CTX.receivedCount = 0; CTX.value = 0xFF; } if OF_LIKELY (CTX.lengths == NULL) - CTX.lengths = of_malloc( + CTX.lengths = of_alloc( CTX.litLenCodesCount + CTX.distCodesCount + 258, 1); for (uint16_t i = CTX.receivedCount; i < CTX.litLenCodesCount + CTX.distCodesCount + 258;) { uint8_t j, count; Index: src/OFLHADecompressingStream.m ================================================================== --- src/OFLHADecompressingStream.m +++ src/OFLHADecompressingStream.m @@ -108,11 +108,11 @@ _distanceBits = distanceBits; _dictionaryBits = dictionaryBits; _slidingWindowMask = (1u << dictionaryBits) - 1; - _slidingWindow = of_malloc(_slidingWindowMask + 1, 1); + _slidingWindow = of_alloc(_slidingWindowMask + 1, 1); memset(_slidingWindow, ' ', _slidingWindowMask + 1); } @catch (id e) { [self release]; @throw e; } @@ -175,11 +175,11 @@ goto start; } _codesCount = bits; _codesReceived = 0; - _codesLengths = of_calloc(bits, 1); + _codesLengths = of_alloc_zeroed(bits, 1); _skip = true; _state = STATE_CODE_LEN_TREE; goto start; case STATE_CODE_LEN_TREE: @@ -256,11 +256,11 @@ goto start; } _codesCount = bits; _codesReceived = 0; - _codesLengths = of_calloc(bits, 1); + _codesLengths = of_alloc_zeroed(bits, 1); _skip = false; _treeIter = _codeLenTree; _state = STATE_LITLEN_TREE; goto start; @@ -346,11 +346,11 @@ goto start; } _codesCount = bits; _codesReceived = 0; - _codesLengths = of_calloc(bits, 1); + _codesLengths = of_alloc_zeroed(bits, 1); _treeIter = _codeLenTree; _state = STATE_DIST_TREE; goto start; case STATE_DIST_TREE: Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -95,11 +95,11 @@ - (of_list_object_t *)appendObject: (id)object { of_list_object_t *listObject; - listObject = of_malloc(1, sizeof(of_list_object_t)); + listObject = of_alloc(1, sizeof(of_list_object_t)); listObject->object = [object retain]; listObject->next = NULL; listObject->previous = _lastListObject; if (_lastListObject != NULL) @@ -118,11 +118,11 @@ - (of_list_object_t *)prependObject: (id)object { of_list_object_t *listObject; - listObject = of_malloc(1, sizeof(of_list_object_t)); + listObject = of_alloc(1, sizeof(of_list_object_t)); listObject->object = [object retain]; listObject->next = _firstListObject; listObject->previous = NULL; if (_firstListObject != NULL) @@ -141,11 +141,11 @@ - (of_list_object_t *)insertObject: (id)object beforeListObject: (of_list_object_t *)listObject { of_list_object_t *newListObject; - newListObject = of_malloc(1, sizeof(of_list_object_t)); + newListObject = of_alloc(1, sizeof(of_list_object_t)); newListObject->object = [object retain]; newListObject->next = listObject; newListObject->previous = listObject->previous; if (listObject->previous != NULL) @@ -165,11 +165,11 @@ - (of_list_object_t *)insertObject: (id)object afterListObject: (of_list_object_t *)listObject { of_list_object_t *newListObject; - newListObject = of_malloc(1, sizeof(of_list_object_t)); + newListObject = of_alloc(1, sizeof(of_list_object_t)); newListObject->object = [object retain]; newListObject->next = listObject->next; newListObject->previous = listObject; if (listObject->next != NULL) @@ -299,11 +299,11 @@ previous = NULL; @try { for (of_list_object_t *iter = _firstListObject; iter != NULL; iter = iter->next) { - listObject = of_malloc(1, sizeof(of_list_object_t)); + listObject = of_alloc(1, sizeof(of_list_object_t)); listObject->object = [iter->object retain]; listObject->next = NULL; listObject->previous = previous; if (copy->_firstListObject == NULL) Index: src/OFMapTable.m ================================================================== --- src/OFMapTable.m +++ src/OFMapTable.m @@ -161,11 +161,11 @@ _capacity *= 2; if (_capacity < MIN_CAPACITY) _capacity = MIN_CAPACITY; - _buckets = of_calloc(_capacity, sizeof(*_buckets)); + _buckets = of_alloc_zeroed(_capacity, sizeof(*_buckets)); if (of_hash_seed != 0) _rotate = of_random16() & 31; } @catch (id e) { [self release]; @@ -323,11 +323,11 @@ * below the minimum capacity. */ if ((capacity < _capacity && count > _count) || capacity < MIN_CAPACITY) return; - buckets = of_calloc(capacity, sizeof(*buckets)); + buckets = of_alloc_zeroed(capacity, sizeof(*buckets)); for (unsigned long i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deleted) { unsigned long j, last; @@ -412,11 +412,11 @@ } if (i >= last) @throw [OFOutOfRangeException exception]; - bucket = of_malloc(1, sizeof(*bucket)); + bucket = of_alloc(1, sizeof(*bucket)); @try { bucket->key = _keyFunctions.retain(key); } @catch (id e) { free(bucket); Index: src/OFMapTableDictionary.m ================================================================== --- src/OFMapTableDictionary.m +++ src/OFMapTableDictionary.m @@ -342,11 +342,11 @@ OFArray *ret; id *keys; size_t count; count = _mapTable.count; - keys = of_malloc(count, sizeof(*keys)); + keys = of_alloc(count, sizeof(*keys)); @try { void *pool = objc_autoreleasePoolPush(); OFMapTableEnumerator *enumerator; void **keyPtr; @@ -376,11 +376,11 @@ OFArray *ret; id *objects; size_t count; count = _mapTable.count; - objects = of_malloc(count, sizeof(*objects)); + objects = of_alloc(count, sizeof(*objects)); @try { void *pool = objc_autoreleasePoolPush(); OFMapTableEnumerator *enumerator; void **objectPtr; Index: src/OFMethodSignature.m ================================================================== --- src/OFMethodSignature.m +++ src/OFMethodSignature.m @@ -595,11 +595,11 @@ length = strlen(types); if (length == 0) @throw [OFInvalidFormatException exception]; - _types = of_malloc(length + 1, 1); + _types = of_alloc(length + 1, 1); memcpy(_types, types, length); _typesPointers = [[OFMutableData alloc] initWithItemSize: sizeof(char *)]; _offsets = [[OFMutableData alloc] Index: src/OFMutableAdjacentArray.m ================================================================== --- src/OFMutableAdjacentArray.m +++ src/OFMutableAdjacentArray.m @@ -241,11 +241,11 @@ if (range.length > SIZE_MAX - range.location || range.location >= count || range.length > count - range.location) @throw [OFOutOfRangeException exception]; - copy = of_malloc(range.length, sizeof(*copy)); + copy = of_alloc(range.length, sizeof(*copy)); memcpy(copy, objects + range.location, range.length * sizeof(id)); @try { [_array removeItemsInRange: range]; _mutations++; Index: src/OFMutableData.m ================================================================== --- src/OFMutableData.m +++ src/OFMutableData.m @@ -92,11 +92,11 @@ @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; - _items = of_malloc(capacity, itemSize); + _items = of_alloc(capacity, itemSize); _itemSize = itemSize; _capacity = capacity; _freeWhenDone = true; } @catch (id e) { [self release]; Index: src/OFMutableSet.m ================================================================== --- src/OFMutableSet.m +++ src/OFMutableSet.m @@ -170,11 +170,11 @@ { void *pool = objc_autoreleasePoolPush(); size_t count = self.count; id *cArray; - cArray = of_malloc(count, sizeof(id)); + cArray = of_alloc(count, sizeof(id)); @try { size_t i; i = 0; for (id object in self) { Index: src/OFMutableUTF8String.m ================================================================== --- src/OFMutableUTF8String.m +++ src/OFMutableUTF8String.m @@ -99,11 +99,11 @@ return; } unicodeLen = self.length; - unicodeString = of_malloc(unicodeLen, sizeof(of_unichar_t)); + unicodeString = of_alloc(unicodeLen, sizeof(of_unichar_t)); i = j = 0; newCStringLength = 0; while (i < _s->cStringLength) { @@ -153,11 +153,11 @@ i += cLen; } @try { - newCString = of_malloc(newCStringLength + 1, 1); + newCString = of_alloc(newCStringLength + 1, 1); } @catch (id e) { free(unicodeString); @throw e; } @@ -373,11 +373,11 @@ } - (void)appendCharacters: (const of_unichar_t *)characters length: (size_t)length { - char *tmp = of_malloc((length * 4) + 1, 1); + char *tmp = of_alloc((length * 4) + 1, 1); @try { size_t j = 0; bool isUTF8 = false; Index: src/OFObject+KeyValueCoding.m ================================================================== --- src/OFObject+KeyValueCoding.m +++ src/OFObject+KeyValueCoding.m @@ -48,11 +48,11 @@ if ((keyLength = key.UTF8StringLength) < 1) { objc_autoreleasePoolPop(pool); return [self valueForUndefinedKey: key]; } - name = of_malloc(keyLength + 3, 1); + name = of_alloc(keyLength + 3, 1); @try { memcpy(name, "is", 2); memcpy(name + 2, key.UTF8String, keyLength); name[keyLength + 2] = '\0'; @@ -160,11 +160,11 @@ [self setValue: value forUndefinedKey: key]; return; } - name = of_malloc(keyLength + 5, 1); + name = of_alloc(keyLength + 5, 1); @try { memcpy(name, "set", 3); memcpy(name + 3, key.UTF8String, keyLength); memcpy(name + keyLength + 3, ":", 2); Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -1237,11 +1237,12 @@ #ifdef __cplusplus extern "C" { #endif /** - * @brief Allocates memory for the specified number of items. + * @brief Allocates memory for the specified number of items of the specified + * size. * * To free the allocated memory, use `free()`. * * Throws @ref OFOutOfMemoryException if allocating failed and * @ref OFOutOfRangeException if the requested size exceeds the address space. @@ -1249,16 +1250,16 @@ * @param count The number of items to allocate * @param size The size of each item to allocate * @return A pointer to the allocated memory. May return NULL if the specified * size or count is 0. */ -extern void *_Nullable of_malloc(size_t count, size_t size) +extern void *_Nullable of_alloc(size_t count, size_t size) OF_WARN_UNUSED_RESULT; /** - * @brief Allocates memory for the specified number of items and initializes it - * with zeros. + * @brief Allocates memory for the specified number of items of the specified + * size and initializes it with zeros. * * To free the allocated memory, use `free()`. * * Throws @ref OFOutOfMemoryException if allocating failed and * @ref OFOutOfRangeException if the requested size exceeds the address space. @@ -1266,15 +1267,15 @@ * @param size The size of each item to allocate * @param count The number of items to allocate * @return A pointer to the allocated memory. May return NULL if the specified * size or count is 0. */ -extern void *_Nullable of_calloc(size_t count, size_t size) +extern void *_Nullable of_alloc_zeroed(size_t count, size_t size) OF_WARN_UNUSED_RESULT; /** - * @brief Resizes memory to the specific number of items of the specified size. + * @brief Resizes memory to the specified number of items of the specified size. * * To free the allocated memory, use `free()`. * * If the pointer is NULL, this is equivalent to allocating memory. * If the size or number of items is 0, this is equivalent to freeing memory. Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -97,11 +97,11 @@ } allocFailedException; uint32_t of_hash_seed; void * -of_malloc(size_t count, size_t size) +of_alloc(size_t count, size_t size) { void *pointer; if OF_UNLIKELY (count == 0 || size == 0) return NULL; @@ -115,11 +115,11 @@ return pointer; } void * -of_calloc(size_t count, size_t size) +of_alloc_zeroed(size_t count, size_t size) { void *pointer; if OF_UNLIKELY (count == 0 || size == 0) return NULL; Index: src/OFOptionsParser.m ================================================================== --- src/OFOptionsParser.m +++ src/OFOptionsParser.m @@ -84,11 +84,11 @@ *iter->argumentPtr = nil; count++; } - _options = of_malloc(count + 1, sizeof(*_options)); + _options = of_alloc(count + 1, sizeof(*_options)); _longOptions = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions]; for (iter = options, iter2 = _options; Index: src/OFPollKernelEventObserver.m ================================================================== --- src/OFPollKernelEventObserver.m +++ src/OFPollKernelEventObserver.m @@ -50,11 +50,11 @@ _FDs = [[OFMutableData alloc] initWithItemSize: sizeof(struct pollfd)]; [_FDs addItem: &p]; _maxFD = _cancelFD[0]; - _FDToObject = of_malloc((size_t)_maxFD + 1, sizeof(id)); + _FDToObject = of_alloc((size_t)_maxFD + 1, sizeof(id)); } @catch (id e) { [self release]; @throw e; } Index: src/OFSecureData.m ================================================================== --- src/OFSecureData.m +++ src/OFSecureData.m @@ -138,13 +138,13 @@ return page; } } - page = of_malloc(1, sizeof(*page)); + page = of_alloc(1, sizeof(*page)); @try { - page->map = of_calloc(1, mapSize); + page->map = of_alloc_zeroed(1, mapSize); } @catch (id e) { free(page); @throw e; } @try { @@ -292,11 +292,11 @@ size_t i; if (preallocatedPages != NULL) @throw [OFInvalidArgumentException exception]; - preallocatedPages = of_calloc(numPages, sizeof(struct page)); + preallocatedPages = of_alloc_zeroed(numPages, sizeof(struct page)); # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) of_tlskey_set(preallocatedPagesKey, preallocatedPages); # endif @try { @@ -413,11 +413,11 @@ if (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exception]; if (allowsSwappableMemory) { - _items = of_malloc(count, itemSize); + _items = of_alloc(count, itemSize); _freeWhenDone = true; memset(_items, 0, count * itemSize); #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) } else if (count * itemSize >= pageSize) _items = mapPages(OF_ROUND_UP_POW2(pageSize, Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -149,11 +149,11 @@ length: MIN_READ_SIZE]; if (bytesRead > length) { memcpy(buffer, tmp, length); - readBuffer = of_malloc(bytesRead - length, 1); + readBuffer = of_alloc(bytesRead - length, 1); memcpy(readBuffer, tmp + length, bytesRead - length); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength = bytesRead - length; @@ -641,11 +641,11 @@ char *buffer; if OF_UNLIKELY (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exception]; - buffer = of_malloc(count, itemSize); + buffer = of_alloc(count, itemSize); @try { [self readIntoBuffer: buffer exactLength: count * itemSize]; ret = [OFData dataWithItemsNoCopy: buffer @@ -662,11 +662,11 @@ - (OFData *)readDataUntilEndOfStream { OFMutableData *data = [OFMutableData data]; size_t pageSize = [OFSystemInfo pageSize]; - char *buffer = of_malloc(1, pageSize); + char *buffer = of_alloc(1, pageSize); @try { while (!self.atEndOfStream) { size_t length; @@ -692,11 +692,11 @@ - (OFString *)readStringWithLength: (size_t)length encoding: (of_string_encoding_t)encoding { OFString *ret; - char *buffer = of_malloc(length + 1, 1); + char *buffer = of_alloc(length + 1, 1); buffer[length] = 0; @try { [self readIntoBuffer: buffer exactLength: length]; @@ -739,11 +739,11 @@ } } /* Read and see if we got a newline or \0 */ pageSize = [OFSystemInfo pageSize]; - buffer = of_malloc(1, pageSize); + buffer = of_alloc(1, pageSize); @try { if ([self lowlevelIsAtEndOfStream]) { size_t retLength; @@ -775,11 +775,11 @@ /* Look if there's a newline or \0 */ for (size_t i = 0; i < bufferLength; i++) { if OF_UNLIKELY (buffer[i] == '\n' || buffer[i] == '\0') { size_t retLength = _readBufferLength + i; - char *retCString = of_malloc(retLength, 1); + char *retCString = of_alloc(retLength, 1); if (_readBuffer != NULL) memcpy(retCString, _readBuffer, _readBufferLength); memcpy(retCString + _readBufferLength, @@ -798,11 +798,11 @@ if (bufferLength > 0) { /* * Append data to _readBuffer * to prevent loss of data. */ - readBuffer = of_malloc( + readBuffer = of_alloc( _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); @@ -820,11 +820,11 @@ @throw e; } @finally { free(retCString); } - readBuffer = of_malloc(bufferLength - i - 1, 1); + readBuffer = of_alloc(bufferLength - i - 1, 1); if (readBuffer != NULL) memcpy(readBuffer, buffer + i + 1, bufferLength - i - 1); free(_readBufferMemory); @@ -836,11 +836,11 @@ } } /* There was no newline or \0 */ if (bufferLength > 0) { - readBuffer = of_malloc(_readBufferLength + bufferLength, + readBuffer = of_alloc(_readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); @@ -977,11 +977,11 @@ } } /* Read and see if we got a delimiter or \0 */ pageSize = [OFSystemInfo pageSize]; - buffer = of_malloc(1, pageSize); + buffer = of_alloc(1, pageSize); @try { if ([self lowlevelIsAtEndOfStream]) { if (_readBuffer == NULL) { _waitingForDelimiter = false; @@ -1015,11 +1015,11 @@ if (buffer[i] == '\0') delimiterLength = 1; retLength = _readBufferLength + i + 1 - delimiterLength; - retCString = of_malloc(retLength, 1); + retCString = of_alloc(retLength, 1); if (_readBuffer != NULL && _readBufferLength <= retLength) memcpy(retCString, _readBuffer, _readBufferLength); @@ -1039,11 +1039,11 @@ if (bufferLength > 0) { /* * Append data to _readBuffer * to prevent loss of data. */ - readBuffer = of_malloc( + readBuffer = of_alloc( _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); @@ -1061,11 +1061,11 @@ @throw e; } @finally { free(retCString); } - readBuffer = of_malloc(bufferLength - i - 1, 1); + readBuffer = of_alloc(bufferLength - i - 1, 1); if (readBuffer != NULL) memcpy(readBuffer, buffer + i + 1, bufferLength - i - 1); free(_readBufferMemory); @@ -1077,11 +1077,11 @@ } } /* Neither the delimiter nor \0 was found */ if (bufferLength > 0) { - readBuffer = of_malloc(_readBufferLength + bufferLength, + readBuffer = of_alloc(_readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); @@ -1334,11 +1334,11 @@ #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint16_t *tmp = of_malloc(count, sizeof(uint16_t)); + uint16_t *tmp = of_alloc(count, sizeof(uint16_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP16(buffer[i]); @@ -1364,11 +1364,11 @@ #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint32_t *tmp = of_malloc(count, sizeof(uint32_t)); + uint32_t *tmp = of_alloc(count, sizeof(uint32_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP32(buffer[i]); @@ -1394,11 +1394,11 @@ #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint64_t *tmp = of_malloc(count, sizeof(uint64_t)); + uint64_t *tmp = of_alloc(count, sizeof(uint64_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP64(buffer[i]); @@ -1424,11 +1424,11 @@ #ifdef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - float *tmp = of_malloc(count, sizeof(float)); + float *tmp = of_alloc(count, sizeof(float)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_FLOAT(buffer[i]); @@ -1454,11 +1454,11 @@ #ifdef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - double *tmp = of_malloc(count, sizeof(double)); + double *tmp = of_alloc(count, sizeof(double)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_DOUBLE(buffer[i]); @@ -1524,11 +1524,11 @@ #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint16_t *tmp = of_malloc(count, sizeof(uint16_t)); + uint16_t *tmp = of_alloc(count, sizeof(uint16_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP16(buffer[i]); @@ -1554,11 +1554,11 @@ #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint32_t *tmp = of_malloc(count, sizeof(uint32_t)); + uint32_t *tmp = of_alloc(count, sizeof(uint32_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP32(buffer[i]); @@ -1584,11 +1584,11 @@ #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint64_t *tmp = of_malloc(count, sizeof(uint64_t)); + uint64_t *tmp = of_alloc(count, sizeof(uint64_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP64(buffer[i]); @@ -1614,11 +1614,11 @@ #ifndef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - float *tmp = of_malloc(count, sizeof(float)); + float *tmp = of_alloc(count, sizeof(float)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_FLOAT(buffer[i]); @@ -1644,11 +1644,11 @@ #ifndef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - double *tmp = of_malloc(count, sizeof(double)); + double *tmp = of_alloc(count, sizeof(double)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_DOUBLE(buffer[i]); @@ -1717,11 +1717,11 @@ encoding: (of_string_encoding_t)encoding { size_t stringLength = [string cStringLengthWithEncoding: encoding]; char *buffer; - buffer = of_malloc(stringLength + 1, 1); + buffer = of_alloc(stringLength + 1, 1); @try { memcpy(buffer, [string cStringWithEncoding: encoding], stringLength); buffer[stringLength] = '\n'; @@ -1872,11 +1872,11 @@ char *readBuffer; if (length > SIZE_MAX - _readBufferLength) @throw [OFOutOfRangeException exception]; - readBuffer = of_malloc(_readBufferLength + length, 1); + readBuffer = of_alloc(_readBufferLength + length, 1); memcpy(readBuffer, buffer, length); memcpy(readBuffer + length, _readBuffer, _readBufferLength); free(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; Index: src/OFString+JSONParsing.m ================================================================== --- src/OFString+JSONParsing.m +++ src/OFString+JSONParsing.m @@ -146,11 +146,11 @@ char delimiter = **pointer; if (++(*pointer) + 1 >= stop) return nil; - buffer = of_malloc(stop - *pointer, 1); + buffer = of_alloc(stop - *pointer, 1); while (*pointer < stop) { /* Parse escape codes */ if (**pointer == '\\') { if (++(*pointer) >= stop) { @@ -292,11 +292,11 @@ parseIdentifier(const char **pointer, const char *stop) { char *buffer; size_t i = 0; - buffer = of_malloc(stop - *pointer, 1); + buffer = of_alloc(stop - *pointer, 1); while (*pointer < stop) { if ((**pointer >= 'a' && **pointer <= 'z') || (**pointer >= 'A' && **pointer <= 'Z') || (**pointer >= '0' && **pointer <= '9') || Index: src/OFString+URLEncoding.m ================================================================== --- src/OFString+URLEncoding.m +++ src/OFString+URLEncoding.m @@ -87,11 +87,11 @@ char *retCString; char byte = 0; int state = 0; size_t i = 0; - retCString = of_malloc(length + 1, 1); + retCString = of_alloc(length + 1, 1); while (length--) { char c = *string++; switch (state) { Index: src/OFString+XMLEscaping.m ================================================================== --- src/OFString+XMLEscaping.m +++ src/OFString+XMLEscaping.m @@ -40,11 +40,11 @@ string = self.UTF8String; length = self.UTF8StringLength; j = 0; retLength = length; - retCString = of_malloc(retLength, 1); + retCString = of_alloc(retLength, 1); for (size_t i = 0; i < length; i++) { switch (string[i]) { case '<': append = "<"; Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -1019,11 +1019,11 @@ * to use -[initWithUTF8StringNoCopy:length:freeWhenDone:]. */ if (SIZE_MAX - (size_t)fileSize < 1) @throw [OFOutOfRangeException exception]; - tmp = of_malloc((size_t)fileSize + 1, 1); + tmp = of_alloc((size_t)fileSize + 1, 1); @try { file = [[OFFile alloc] initWithPath: path mode: @"r"]; [file readIntoBuffer: tmp @@ -1380,11 +1380,11 @@ char *cString; size_t cStringLength; switch (encoding) { case OF_STRING_ENCODING_UTF_8: - cString = of_malloc((length * 4) + 1, 1); + cString = of_alloc((length * 4) + 1, 1); @try { cStringLength = [self of_getCString: cString maxLength: (length * 4) + 1 @@ -1413,11 +1413,11 @@ case OF_STRING_ENCODING_CODEPAGE_850: case OF_STRING_ENCODING_CODEPAGE_858: case OF_STRING_ENCODING_MAC_ROMAN: case OF_STRING_ENCODING_KOI8_R: case OF_STRING_ENCODING_KOI8_U: - cString = of_malloc(length + 1, 1); + cString = of_alloc(length + 1, 1); @try { cStringLength = [self of_getCString: cString maxLength: length + 1 encoding: encoding @@ -1867,11 +1867,11 @@ pool = objc_autoreleasePoolPush(); searchCharacters = string.characters; - characters = of_malloc(range.length, sizeof(of_unichar_t)); + characters = of_alloc(range.length, sizeof(of_unichar_t)); @try { [self getCharacters: characters inRange: range]; if (options & OF_STRING_SEARCH_BACKWARDS) { @@ -1935,11 +1935,11 @@ return OF_NOT_FOUND; if (range.length > SIZE_MAX / sizeof(of_unichar_t)) @throw [OFOutOfRangeException exception]; - characters = of_malloc(range.length, sizeof(of_unichar_t)); + characters = of_alloc(range.length, sizeof(of_unichar_t)); @try { [self getCharacters: characters inRange: range]; if (options & OF_STRING_SEARCH_BACKWARDS) { @@ -2178,11 +2178,11 @@ bool hasPrefix; if ((prefixLength = prefix.length) > self.length) return false; - tmp = of_malloc(prefixLength, sizeof(of_unichar_t)); + tmp = of_alloc(prefixLength, sizeof(of_unichar_t)); @try { void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: of_range(0, prefixLength)]; @@ -2208,11 +2208,11 @@ if ((suffixLength = suffix.length) > self.length) return false; length = self.length; - tmp = of_malloc(suffixLength, sizeof(of_unichar_t)); + tmp = of_alloc(suffixLength, sizeof(of_unichar_t)); @try { void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: of_range(length - suffixLength, @@ -2501,11 +2501,11 @@ - (const of_unichar_t *)characters { size_t length = self.length; of_unichar_t *buffer; - buffer = of_malloc(length, sizeof(of_unichar_t)); + buffer = of_alloc(length, sizeof(of_unichar_t)); @try { [self getCharacters: buffer inRange: of_range(0, length)]; return [[OFData dataWithItemsNoCopy: buffer @@ -2531,11 +2531,11 @@ of_char16_t *buffer; size_t j; bool swap = (byteOrder != OF_BYTE_ORDER_NATIVE); /* Allocate memory for the worst case */ - buffer = of_malloc((length + 1) * 2, sizeof(of_char16_t)); + buffer = of_alloc((length + 1) * 2, sizeof(of_char16_t)); j = 0; for (size_t i = 0; i < length; i++) { of_unichar_t c = characters[i]; @@ -2603,11 +2603,11 @@ - (const of_char32_t *)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder { size_t length = self.length; of_char32_t *buffer; - buffer = of_malloc(length + 1, sizeof(of_char32_t)); + buffer = of_alloc(length + 1, sizeof(of_char32_t)); @try { [self getCharacters: buffer inRange: of_range(0, length)]; buffer[length] = 0; Index: src/OFUTF8String.m ================================================================== --- src/OFUTF8String.m +++ src/OFUTF8String.m @@ -179,11 +179,11 @@ self = [super init]; @try { _s = &_storage; - _s->cString = of_calloc(1, 1); + _s->cString = of_alloc_zeroed(1, 1); _s->freeWhenDone = true; } @catch (id e) { [self release]; @throw e; } @@ -245,11 +245,11 @@ cStringLength -= 3; } _s = &_storage; - _s->cString = of_malloc(cStringLength + 1, 1); + _s->cString = of_alloc(cStringLength + 1, 1); _s->cStringLength = cStringLength; _s->freeWhenDone = true; if (encoding == OF_STRING_ENCODING_UTF_8 || encoding == OF_STRING_ENCODING_ASCII) { @@ -450,11 +450,11 @@ else _s->isUTF8 = true; _s->length = string.length; - _s->cString = of_malloc(_s->cStringLength + 1, 1); + _s->cString = of_alloc(_s->cStringLength + 1, 1); memcpy(_s->cString, string.UTF8String, _s->cStringLength + 1); _s->freeWhenDone = true; } @catch (id e) { [self release]; @throw e; @@ -471,11 +471,11 @@ @try { size_t j; _s = &_storage; - _s->cString = of_malloc((length * 4) + 1, 1); + _s->cString = of_alloc((length * 4) + 1, 1); _s->length = length; _s->freeWhenDone = true; j = 0; for (size_t i = 0; i < length; i++) { @@ -527,11 +527,11 @@ } else if (byteOrder != OF_BYTE_ORDER_NATIVE) swap = true; _s = &_storage; - _s->cString = of_malloc((length * 4) + 1, 1); + _s->cString = of_alloc((length * 4) + 1, 1); _s->length = length; _s->freeWhenDone = true; j = 0; for (size_t i = 0; i < length; i++) { @@ -612,11 +612,11 @@ } else if (byteOrder != OF_BYTE_ORDER_NATIVE) swap = true; _s = &_storage; - _s->cString = of_malloc((length * 4) + 1, 1); + _s->cString = of_alloc((length * 4) + 1, 1); _s->length = length; _s->freeWhenDone = true; j = 0; for (size_t i = 0; i < length; i++) { @@ -687,11 +687,11 @@ break; case -1: @throw [OFInvalidEncodingException exception]; } - _s->cString = of_malloc(cStringLength + 1, 1); + _s->cString = of_alloc(cStringLength + 1, 1); memcpy(_s->cString, tmp, cStringLength + 1); _s->freeWhenDone = true; } @finally { free(tmp); } @@ -1153,11 +1153,11 @@ return array; } - (const of_unichar_t *)characters { - of_unichar_t *buffer = of_malloc(_s->length, sizeof(of_unichar_t)); + of_unichar_t *buffer = of_alloc(_s->length, sizeof(of_unichar_t)); size_t i = 0, j = 0; while (i < _s->cStringLength) { of_unichar_t c; ssize_t cLen; @@ -1180,11 +1180,11 @@ freeWhenDone: true] items]; } - (const of_char32_t *)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder { - of_char32_t *buffer = of_malloc(_s->length + 1, sizeof(of_char32_t)); + of_char32_t *buffer = of_alloc(_s->length + 1, sizeof(of_char32_t)); size_t i = 0, j = 0; while (i < _s->cStringLength) { of_char32_t c; ssize_t cLen; Index: src/OFValue.m ================================================================== --- src/OFValue.m +++ src/OFValue.m @@ -181,13 +181,13 @@ if (strcmp([object objCType], objCType) != 0) return false; size = of_sizeof_type_encoding(objCType); - value = of_malloc(1, size); + value = of_alloc(1, size); @try { - otherValue = of_malloc(1, size); + otherValue = of_alloc(1, size); } @catch (id e) { free(value); @throw e; } @@ -210,11 +210,11 @@ { size_t size = of_sizeof_type_encoding(self.objCType); unsigned char *value; uint32_t hash; - value = of_malloc(1, size); + value = of_alloc(1, size); @try { [self getValue: value size: size]; OF_HASH_INIT(hash); @@ -311,11 +311,11 @@ OFMutableString *ret = [OFMutableString stringWithString: @" UINT32_MAX) @throw [OFOutOfRangeException exception]; - UTF16 = of_malloc(length, sizeof(of_char16_t)); + UTF16 = of_alloc(length, sizeof(of_char16_t)); @try { DWORD UTF16Len; OFMutableData *rest = nil; size_t i = 0; @@ -362,11 +362,11 @@ _incompleteUTF8SurrogateLen = 0; i += toCopy; } - tmp = of_malloc(length * 2, sizeof(of_char16_t)); + tmp = of_alloc(length * 2, sizeof(of_char16_t)); @try { DWORD bytesWritten; while (i < length) { of_unichar_t c; Index: src/OFXMLComment.m ================================================================== --- src/OFXMLComment.m +++ src/OFXMLComment.m @@ -114,11 +114,11 @@ level: (unsigned int)level { OFString *ret; if (indentation > 0 && level > 0) { - char *whitespaces = of_malloc((level * indentation) + 1, 1); + char *whitespaces = of_alloc((level * indentation) + 1, 1); memset(whitespaces, ' ', level * indentation); whitespaces[level * indentation] = 0; @try { ret = [OFString stringWithFormat: @"%s", Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -460,11 +460,11 @@ else defaultNS = _defaultNamespace; i = 0; length = _name.UTF8StringLength + 3 + (level * indentation); - cString = of_malloc(length, 1); + cString = of_alloc(length, 1); @try { memset(cString + i, ' ', level * indentation); i += level * indentation; Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -276,11 +276,11 @@ } - (void)parseStream: (OFStream *)stream { size_t pageSize = [OFSystemInfo pageSize]; - char *buffer = of_malloc(1, pageSize); + char *buffer = of_alloc(1, pageSize); @try { while (!stream.atEndOfStream) { size_t length = [stream readIntoBuffer: buffer length: pageSize]; Index: src/OFXMLProcessingInstructions.m ================================================================== --- src/OFXMLProcessingInstructions.m +++ src/OFXMLProcessingInstructions.m @@ -115,11 +115,11 @@ level: (unsigned int)level { OFString *ret; if (indentation > 0 && level > 0) { - char *whitespaces = of_malloc((level * indentation) + 1, 1); + char *whitespaces = of_alloc((level * indentation) + 1, 1); memset(whitespaces, ' ', level * indentation); whitespaces[level * indentation] = 0; @try { ret = [OFString stringWithFormat: Index: src/huffman_tree.m ================================================================== --- src/huffman_tree.m +++ src/huffman_tree.m @@ -28,11 +28,11 @@ static struct of_huffman_tree * newTree(void) { struct of_huffman_tree *tree; - tree = of_malloc(1, sizeof(*tree)); + tree = of_alloc(1, sizeof(*tree)); tree->leaves[0] = tree->leaves[1] = NULL; tree->value = 0xFFFF; return tree; } Index: src/platform/posix/OFProcess.m ================================================================== --- src/platform/posix/OFProcess.m +++ src/platform/posix/OFProcess.m @@ -240,11 +240,11 @@ { OFString *const *objects = arguments.objects; size_t i, count = arguments.count; of_string_encoding_t encoding; - *argv = of_malloc(count + 2, sizeof(char *)); + *argv = of_alloc(count + 2, sizeof(char *)); encoding = [OFLocale encoding]; (*argv)[0] = (char *)[programName cStringWithEncoding: encoding]; @@ -265,11 +265,11 @@ return NULL; encoding = [OFLocale encoding]; count = environment.count; - envp = of_calloc(count + 1, sizeof(char *)); + envp = of_alloc_zeroed(count + 1, sizeof(char *)); @try { OFEnumerator *keyEnumerator = [environment keyEnumerator]; OFEnumerator *objectEnumerator = [environment objectEnumerator]; @@ -283,11 +283,11 @@ keyLen = [key cStringLengthWithEncoding: encoding]; objectLen = [object cStringLengthWithEncoding: encoding]; - envp[i] = of_malloc(keyLen + objectLen + 2, 1); + envp[i] = of_alloc(keyLen + objectLen + 2, 1); memcpy(envp[i], [key cStringWithEncoding: encoding], keyLen); envp[i][keyLen] = '='; memcpy(envp[i] + keyLen + 1, Index: src/platform/windows/OFProcess.m ================================================================== --- src/platform/windows/OFProcess.m +++ src/platform/windows/OFProcess.m @@ -193,11 +193,12 @@ si.hStdOutput = _readPipe[1]; si.hStdError = GetStdHandle(STD_ERROR_HANDLE); si.dwFlags |= STARTF_USESTDHANDLES; length = argumentsString.UTF16StringLength; - argumentsCopy = of_malloc(length + 1, sizeof(of_char16_t)); + argumentsCopy = of_alloc(length + 1, + sizeof(of_char16_t)); memcpy(argumentsCopy, argumentsString.UTF16String, (length + 1) * 2); @try { if (!CreateProcessW(program.UTF16String, argumentsCopy, NULL, NULL, TRUE, Index: tests/OFDataTests.m ================================================================== --- tests/OFDataTests.m +++ tests/OFDataTests.m @@ -34,12 +34,12 @@ of_range_t range; TEST(@"+[dataWithItemSize:]", (mutable = [OFMutableData dataWithItemSize: 4096])) - raw[0] = of_malloc(1, 4096); - raw[1] = of_malloc(1, 4096); + raw[0] = of_alloc(1, 4096); + raw[1] = of_alloc(1, 4096); memset(raw[0], 0xFF, 4096); memset(raw[1], 0x42, 4096); TEST(@"-[addItem:]", R([mutable addItem: raw[0]]) && R([mutable addItem: raw[1]])) Index: tests/OFStreamTests.m ================================================================== --- tests/OFStreamTests.m +++ tests/OFStreamTests.m @@ -69,11 +69,11 @@ size_t pageSize = [OFSystemInfo pageSize]; StreamTester *t = [[[StreamTester alloc] init] autorelease]; OFString *str; char *cstr; - cstr = of_malloc(pageSize - 2, 1); + cstr = of_alloc(pageSize - 2, 1); memset(cstr, 'X', pageSize - 3); cstr[pageSize - 3] = '\0'; TEST(@"-[readLine]", [[t readLine] isEqual: @"foo"] && [(str = [t readLine]) length] == pageSize - 3 && Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -302,11 +302,11 @@ forKey: @"User-Agent"]; _HTTPClient = [[OFHTTPClient alloc] init]; _HTTPClient.delegate = self; - _buffer = of_malloc(1, [OFSystemInfo pageSize]); + _buffer = of_alloc(1, [OFSystemInfo pageSize]); } @catch (id e) { [self release]; @throw e; }