From 10c310db5ee7c31ae809491db2b3c51c0b9bb56c Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Tue, 30 Apr 2019 15:36:21 +0200 Subject: [PATCH] use memcpy instead of strcpy on WString.cpp I can happen String carries binary data, this simple update allows it. Also, memcpy is more efficient than strcpy when size is known. It's an harmless temporary fix until Webserver's painful arg("plain") can be worked out. --- cores/esp8266/WString.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cores/esp8266/WString.cpp b/cores/esp8266/WString.cpp index 69444696aa..3bae7c424e 100644 --- a/cores/esp8266/WString.cpp +++ b/cores/esp8266/WString.cpp @@ -206,7 +206,7 @@ String & String::copy(const char *cstr, unsigned int length) { return *this; } setLen(length); - strcpy(wbuffer(), cstr); + memcpy(wbuffer(), cstr, length + 1); return *this; } @@ -216,7 +216,7 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length) { return *this; } setLen(length); - strcpy_P(wbuffer(), (PGM_P)pstr); + memcpy_P(wbuffer(), (PGM_P)pstr, length + 1); return *this; } @@ -224,7 +224,7 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length) { void String::move(String &rhs) { if(buffer()) { if(capacity() >= rhs.len()) { - strcpy(wbuffer(), rhs.buffer()); + memcpy(wbuffer(), rhs.buffer(), rhs.length() + 1); setLen(rhs.len()); rhs.invalidate(); return; @@ -326,7 +326,7 @@ unsigned char String::concat(const char *cstr, unsigned int length) { return 1; if(!reserve(newlen)) return 0; - strcpy(wbuffer() + len(), cstr); + memcpy(wbuffer() + len(), cstr, length + 1); setLen(newlen); return 1; }