@@ -174,7 +174,7 @@ String & String::copy(const char *cstr, unsigned int length)
174174 return *this ;
175175 }
176176 len = length;
177- strcpy (buffer, cstr);
177+ memcpy (buffer, cstr, length + 1 );
178178 return *this ;
179179}
180180
@@ -185,7 +185,7 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length)
185185 return *this ;
186186 }
187187 len = length;
188- strcpy_P (buffer, (PGM_P)pstr);
188+ memcpy_P (buffer, (PGM_P)pstr, length + 1 );
189189 return *this ;
190190}
191191
@@ -194,7 +194,7 @@ void String::move(String &rhs)
194194{
195195 if (buffer) {
196196 if (rhs && capacity >= rhs.len ) {
197- strcpy (buffer, rhs.buffer );
197+ memcpy (buffer, rhs.buffer , rhs. len + 1 );
198198 len = rhs.len ;
199199 rhs.len = 0 ;
200200 return ;
@@ -266,8 +266,9 @@ unsigned char String::concat(const char *cstr, unsigned int length)
266266 if (!cstr) return 0 ;
267267 if (length == 0 ) return 1 ;
268268 if (!reserve (newlen)) return 0 ;
269- strcpy (buffer + len, cstr);
269+ memcpy (buffer + len, cstr, length );
270270 len = newlen;
271+ buffer[len] = 0 ;
271272 return 1 ;
272273}
273274
@@ -341,7 +342,7 @@ unsigned char String::concat(const __FlashStringHelper * str)
341342 if (length == 0 ) return 1 ;
342343 unsigned int newlen = len + length;
343344 if (!reserve (newlen)) return 0 ;
344- strcpy_P (buffer + len, (const char *) str);
345+ memcpy_P (buffer + len, (const char *) str, length + 1 );
345346 len = newlen;
346347 return 1 ;
347348}
@@ -653,6 +654,7 @@ void String::replace(const String& find, const String& replace)
653654 }
654655 } else if (diff < 0 ) {
655656 char *writeTo = buffer;
657+ char *end = buffer + len;
656658 while ((foundAt = strstr (readFrom, find.buffer )) != NULL ) {
657659 unsigned int n = foundAt - readFrom;
658660 memcpy (writeTo, readFrom, n);
@@ -662,7 +664,7 @@ void String::replace(const String& find, const String& replace)
662664 readFrom = foundAt + find.len ;
663665 len += diff;
664666 }
665- strcpy (writeTo, readFrom);
667+ memcpy (writeTo, readFrom, end - readFrom + 1 );
666668 } else {
667669 unsigned int size = len; // compute size needed for result
668670 while ((foundAt = strstr (readFrom, find.buffer )) != NULL ) {
0 commit comments