Browse Source

[#2386] fix Android crash due to unaligned read/write

Eli Aloni 6 years ago
parent
commit
db055a02d2
2 changed files with 2 additions and 32 deletions
  1. 1 16
      Source/Urho3D/IO/MemoryBuffer.cpp
  2. 1 16
      Source/Urho3D/IO/VectorBuffer.cpp

+ 1 - 16
Source/Urho3D/IO/MemoryBuffer.cpp

@@ -110,22 +110,7 @@ unsigned MemoryBuffer::Write(const void* data, unsigned size)
     unsigned char* destPtr = &buffer_[position_];
     position_ += size;
 
-    unsigned copySize = size;
-    while (copySize >= sizeof(unsigned))
-    {
-        *((unsigned*)destPtr) = *((unsigned*)srcPtr);
-        srcPtr += sizeof(unsigned);
-        destPtr += sizeof(unsigned);
-        copySize -= sizeof(unsigned);
-    }
-    if (copySize & sizeof(unsigned short))
-    {
-        *((unsigned short*)destPtr) = *((unsigned short*)srcPtr);
-        srcPtr += sizeof(unsigned short);
-        destPtr += sizeof(unsigned short);
-    }
-    if (copySize & 1u)
-        *destPtr = *srcPtr;
+	memcpy(destPtr, srcPtr, size);
 
     return size;
 }

+ 1 - 16
Source/Urho3D/IO/VectorBuffer.cpp

@@ -99,22 +99,7 @@ unsigned VectorBuffer::Write(const void* data, unsigned size)
     unsigned char* destPtr = &buffer_[position_];
     position_ += size;
 
-    unsigned copySize = size;
-    while (copySize >= sizeof(unsigned))
-    {
-        *((unsigned*)destPtr) = *((unsigned*)srcPtr);
-        srcPtr += sizeof(unsigned);
-        destPtr += sizeof(unsigned);
-        copySize -= sizeof(unsigned);
-    }
-    if (copySize & sizeof(unsigned short))
-    {
-        *((unsigned short*)destPtr) = *((unsigned short*)srcPtr);
-        srcPtr += sizeof(unsigned short);
-        destPtr += sizeof(unsigned short);
-    }
-    if (copySize & 1u)
-        *destPtr = *srcPtr;
+	memcpy(destPtr, srcPtr, size);
 
     return size;
 }