aboutsummaryrefslogtreecommitdiff
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 84fb5fa..972e23a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -16,10 +16,12 @@ void buffer_deinit(Buffer *self) {
self->capacity = 0;
}
-static CHECK_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity) {
+static CHECK_RESULT int buffer_ensure_capacity_for(Buffer *self, usize size) {
usize capacity;
void *new_mem;
int alloc_result;
+ usize new_capacity;
+ new_capacity = self->size + size;
if(self->capacity >= new_capacity)
return BUFFER_OK;
@@ -43,8 +45,9 @@ static CHECK_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity)
}
int buffer_append(Buffer *self, void *data, usize size) {
- return_if_error(buffer_ensure_capacity(self, self->size + size));
+ return_if_error(buffer_ensure_capacity_for(self, size));
am_memcpy(self->data + self->size, data, size);
+ self->size += size;
return BUFFER_OK;
}