From 3358ed643b69c0a476eac70745debdce1861c72b Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 30 Sep 2019 14:12:35 +0300 Subject: [PATCH] 0031008: Application Framework - memcpy-param-overlap reported by Clang address sanitizer in LDOM_XmlReader::ReadRecord() Use memmove instead of memcpy because of copy of the possible overlapped source and destination parts of the buffer. --- src/LDOM/LDOM_XmlReader.cxx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/LDOM/LDOM_XmlReader.cxx b/src/LDOM/LDOM_XmlReader.cxx index 944a966f17..66a3cc1ca6 100644 --- a/src/LDOM/LDOM_XmlReader.cxx +++ b/src/LDOM/LDOM_XmlReader.cxx @@ -112,17 +112,20 @@ LDOM_XmlReader::RecordType LDOM_XmlReader::ReadRecord (Standard_IStream& theIStr } else { - // If we are reading some data, save the beginning and preserve the state + // If we are reading some data, save the beginning and preserve the state if (aStartData /* && aState != STATE_WAITING */) { if (myPtr > aStartData) theData.rdbuf()->sputn(aStartData, myPtr - aStartData); aStartData = &myBuffer[0]; } - // Copy the rest of file data to the beginning of buffer + // Copy the rest of file data to the beginning of buffer if (aBytesRest > 0) - memcpy (&myBuffer[0], myPtr, aBytesRest); + { + // do not use memcpy here because aBytesRest may be greater than myPtr-myBuffer, so, overlap + memmove (&myBuffer[0], myPtr, aBytesRest); + } - // Read the full buffer and reset start and end buffer pointers + // Read the full buffer and reset start and end buffer pointers myPtr = &myBuffer[0]; Standard_Size aNBytes;