]> OCCT Git - occt.git/commitdiff
0031008: Application Framework - memcpy-param-overlap reported by Clang address sanit...
authormpv <mpv@opencascade.com>
Mon, 30 Sep 2019 11:12:35 +0000 (14:12 +0300)
committerabv <abv@opencascade.com>
Sat, 19 Oct 2019 09:31:35 +0000 (12:31 +0300)
Use memmove instead of memcpy because of copy of the possible overlapped source and destination parts of the buffer.

src/LDOM/LDOM_XmlReader.cxx

index 944a966f17e54403af328ce596f0027a5c01487d..66a3cc1ca62c69bf6bfd264dc62eb640b8190dfb 100644 (file)
@@ -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;