Skip to content

Commit b99609e

Browse files
committed
Fix undefined behaviour for overlapping String
Port of arduino/ArduinoCore-avr#20 , all credits goes to @earlephilhower
1 parent e952b68 commit b99609e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: api/String.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ void String::remove(unsigned int index, unsigned int count){
698698
if (count > len - index) { count = len - index; }
699699
char *writeTo = buffer + index;
700700
len = len - count;
701-
strncpy(writeTo, buffer + index + count,len - index);
701+
memmove(writeTo, buffer + index + count,len - index);
702702
buffer[len] = 0;
703703
}
704704

@@ -726,7 +726,7 @@ void String::trim(void)
726726
char *end = buffer + len - 1;
727727
while (isspace(*end) && end >= begin) end--;
728728
len = end + 1 - begin;
729-
if (begin > buffer) memcpy(buffer, begin, len);
729+
if (begin > buffer) memmove(buffer, begin, len);
730730
buffer[len] = 0;
731731
}
732732

0 commit comments

Comments
 (0)