Skip to content

Commit 27cfc4e

Browse files
committed
Only perform the strcpy if writeTo and readFrom are different from one another, otherwise valgrind is raising an error (and would be right about doing so).
Valgrind error message: Source and destination overlap in strcpy Further information: https://www.valgrind.org/docs/manual/mc-manual.html#mc-manual.overlap
1 parent 4e295b1 commit 27cfc4e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

api/String.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,8 @@ void String::replace(const String& find, const String& replace)
656656
readFrom = foundAt + find.len;
657657
len += diff;
658658
}
659-
strcpy(writeTo, readFrom);
659+
if (writeTo != readFrom)
660+
strcpy(writeTo, readFrom);
660661
} else {
661662
unsigned int size = len; // compute size needed for result
662663
while ((foundAt = strstr(readFrom, find.buffer)) != NULL) {

0 commit comments

Comments
 (0)