buffer: fix strategy for increasing capacity in buffer

This commit is contained in:
tylen 2024-09-26 12:55:54 +00:00 committed by Vasily Davydov
parent f0db572265
commit ccc67114f9

View File

@ -22,7 +22,7 @@ void buffer_append(Buffer* buffer, const char* str) {
LOG_DEBUG("Entering function %s", __func__);
size_t len = strlen(str);
if (buffer->size + len >= buffer->capacity) {
buffer->capacity *= 2;
buffer->capacity = buffer->size + len;
buffer->data = (char*)cdo_realloc(buffer->data, buffer->capacity);
}
strcpy(buffer->data + buffer->size, str);