From 14366beed939fb0cf14589f2d3ce3deb207d73e5 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 11 Oct 2021 07:49:43 +0100 Subject: [PATCH] Bugfix: String::replace not using memmove (#2384) Can fail when regions overlap --- Sming/Wiring/WString.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sming/Wiring/WString.cpp b/Sming/Wiring/WString.cpp index d32e20afe2..2c6838eebe 100644 --- a/Sming/Wiring/WString.cpp +++ b/Sming/Wiring/WString.cpp @@ -860,14 +860,14 @@ bool String::replace(const char* find_buf, size_t find_len, const char* replace_ char* writeTo = buf; while((foundAt = (char*)memmem(readFrom, end - readFrom, find_buf, find_len)) != nullptr) { size_t n = foundAt - readFrom; - memcpy(writeTo, readFrom, n); + memmove(writeTo, readFrom, n); writeTo += n; memcpy(writeTo, replace_buf, replace_len); writeTo += replace_len; readFrom = foundAt + find_len; len += diff; } - memcpy(writeTo, readFrom, end - readFrom); + memmove(writeTo, readFrom, end - readFrom); setlen(len); } else { size_t size = len; // compute size needed for result