Index: src/OFMutableData.h ================================================================== --- src/OFMutableData.h +++ src/OFMutableData.h @@ -155,10 +155,18 @@ */ - (void)insertItems: (const void *)items atIndex: (size_t)index count: (size_t)count; +/*! + * @brief Increases the count by the specified number. The new items are all + * filled with null bytes. + * + * @param count The count by which to increase the count + */ +- (void)increaseCountBy: (size_t)count; + /*! * @brief Removes the item at the specified index. * * @param index The index of the item to remove */ Index: src/OFMutableData.m ================================================================== --- src/OFMutableData.m +++ src/OFMutableData.m @@ -217,10 +217,26 @@ _items + index * _itemSize, (_count - index) * _itemSize); memcpy(_items + index * _itemSize, items, count * _itemSize); _count += count; } + +- (void)increaseCountBy: (size_t)count +{ + if (count > SIZE_MAX - _count) + @throw [OFOutOfRangeException exception]; + + if (_count + count > _capacity) { + _items = [self resizeMemory: _items + size: _itemSize + count: _count + count]; + _capacity = _count + count; + } + + memset(_items + _count * _itemSize, '\0', count * _itemSize); + _count += count; +} - (void)removeItemAtIndex: (size_t)index { [self removeItemsInRange: of_range(index, 1)]; }