From 3e9dd0474bc09e677ad1a9b9a3fc5ecdb51e6060 Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Sun, 12 Jul 2020 15:45:13 -0700 Subject: [PATCH] Fix memcpy overlap in string_erase --- src/string.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/string.c b/src/string.c index 5092835..1cbed63 100644 --- a/src/string.c +++ b/src/string.c @@ -235,7 +235,10 @@ void string_erase(struct string **s, int index) bytes = SJIS_2BYTE((*s)->text[index]) ? 2 : 1; *s = cow_check(*s); - memcpy((*s)->text + index, (*s)->text + index + bytes, (*s)->size - index - bytes); + size_t size = (*s)->size - index - bytes; + for (size_t i = 0; i < size; i++) { + (*s)->text[index+i] = (*s)->text[index+bytes+i]; + } (*s)->size -= bytes; (*s)->text[(*s)->size] = '\0'; }