From 7c4768a3ddd2e3ca02f226bdb416e65c024f3f81 Mon Sep 17 00:00:00 2001 From: Robear Selwans Date: Mon, 4 May 2026 21:07:10 +0300 Subject: [PATCH] Fixed overlapping push in ev_str --- ev_str.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ev_str.h b/ev_str.h index 29a557c..5ff50a3 100644 --- a/ev_str.h +++ b/ev_str.h @@ -476,6 +476,15 @@ evstring_push_impl( evstr_asserttype(*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? u64 required_capacity = meta->length + sz + 1; while(required_capacity > meta->capacity) { // `<=` because of the null terminator