Fixed overlapping push in ev_str
Run tests / Run tests (push) Successful in 10s

This commit is contained in:
2026-05-04 21:07:10 +03:00
parent 82abc8fee5
commit 7c4768a3dd
+9
View File
@@ -476,6 +476,15 @@ evstring_push_impl(
evstr_asserttype(*s); evstr_asserttype(*s);
struct evstr_meta_t *meta = META(*s); struct evstr_meta_t *meta = META(*s);
// Overlapping ranges, need to copy `data` to keep it alive after growing
if(*s < data + sz && data < *s + meta->length)
{
char *old_data = data;
data = ev_str_malloc(sz);
if(data == NULL) return EV_STR_ERR_OOM;
memcpy(data, old_data, sz);
}
// TODO Find a more efficient approach? // TODO Find a more efficient approach?
u64 required_capacity = meta->length + sz + 1; u64 required_capacity = meta->length + sz + 1;
while(required_capacity > meta->capacity) { // `<=` because of the null terminator while(required_capacity > meta->capacity) { // `<=` because of the null terminator