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