diff --git a/Sources/Plasma/CoreLib/hsStream.cpp b/Sources/Plasma/CoreLib/hsStream.cpp index 099587556d..85a73c2afc 100644 --- a/Sources/Plasma/CoreLib/hsStream.cpp +++ b/Sources/Plasma/CoreLib/hsStream.cpp @@ -629,6 +629,8 @@ uint32_t hsRAMStream::Read(uint32_t byteCount, void * buffer) uint32_t hsRAMStream::Write(uint32_t byteCount, const void* buffer) { + hsAssert(fVector.data(), "Trying to write to a null RAM buffer"); + size_t spaceUntilEof = fVector.size() - fPosition; if (byteCount <= spaceUntilEof) { memcpy(fVector.data() + fPosition, buffer, byteCount); @@ -957,26 +959,6 @@ bool hsQueueStream::AtEnd() // hsBufferedStream /////////////////////////////////////////////////////////////////////////////// -inline void FastByteCopy(void* dest, const void* src, uint32_t bytes) -{ - // Don't use memcpy if the read is 4 bytes or less, it's faster to just do a - // direct copy - switch (bytes) - { - case 4: - *((uint32_t*)dest) = *((const uint32_t*)src); - break; - case 2: - *((uint16_t*)dest) = *((const uint16_t*)src); - break; - case 1: - *((uint8_t*)dest) = *((const uint8_t*)src); - break; - default: - memcpy(dest, src, bytes); - } -} - //#define LOG_BUFFERED hsBufferedStream::hsBufferedStream() @@ -1081,7 +1063,7 @@ uint32_t hsBufferedStream::Read(uint32_t bytes, void* buffer) uint32_t bytesInBuffer = fBufferLen - bufferPos; uint32_t cachedReadSize = bytesInBuffer < bytes ? bytesInBuffer : bytes; - FastByteCopy(buffer, &fBuffer[bufferPos], cachedReadSize); + memcpy(buffer, &fBuffer[bufferPos], cachedReadSize); fPosition += cachedReadSize; numReadBytes += cachedReadSize; diff --git a/Sources/Plasma/NucleusLib/pnUUID/pnUUID_Unix.cpp b/Sources/Plasma/NucleusLib/pnUUID/pnUUID_Unix.cpp index 5e7a4d609d..88a9784d3f 100644 --- a/Sources/Plasma/NucleusLib/pnUUID/pnUUID_Unix.cpp +++ b/Sources/Plasma/NucleusLib/pnUUID/pnUUID_Unix.cpp @@ -50,41 +50,28 @@ static_assert(sizeof(plUUID) == sizeof(uuid_t), "plUUID and uuid_t types differ struct plUUIDHelper { - typedef struct _GUID { - uint32_t Data1; - uint16_t Data2; - uint16_t Data3; - uint8_t Data4[8]; - } GUID; - - static inline void CopyToPlasma( plUUID * dst, const uuid_t & src ) + static inline void CopyToPlasma(plUUID* dst, const uuid_t& src) { - hsAssert( sizeof(uuid_t)==sizeof(dst->fData), "sizeof(uuid_t)!=sizeof(plUUID)" ); - memcpy( (void*)dst->fData, (const void *)src, sizeof( plUUID ) ); - - /* - GUIDs are always internally encoded in little endian, - while the uuid_t structure is big endian. - */ - GUID* guid = reinterpret_cast(dst->fData); - guid->Data1 = hsSwapEndian32(guid->Data1); - guid->Data2 = hsSwapEndian16(guid->Data2); - guid->Data3 = hsSwapEndian16(guid->Data3); + memcpy(dst->fData, src, sizeof(plUUID)); + + // plUUIDs need to always be encoded in little endian, but the uuid_t struct is big endian + // This isn't guaranteed to be 32-bit-aligned, so casting to uint16_t/uint32_t pointers is UB + std::swap(dst->fData[0], dst->fData[3]); + std::swap(dst->fData[1], dst->fData[2]); + std::swap(dst->fData[4], dst->fData[5]); + std::swap(dst->fData[6], dst->fData[7]); } - static inline void CopyToNative( uuid_t & dst, const plUUID * src ) + static inline void CopyToNative(uuid_t& dst, const plUUID* src) { - hsAssert( sizeof(uuid_t)==sizeof(src->fData), "sizeof(uuid_t)!=sizeof(plUUID)" ); - memcpy( (void*)dst, (const void *)src->fData, sizeof( plUUID ) ); - - /* - GUIDs are always internally encoded in little endian, - while the uuid_t structure is big endian. - */ - GUID* guid = reinterpret_cast(dst); - guid->Data1 = hsSwapEndian32(guid->Data1); - guid->Data2 = hsSwapEndian16(guid->Data2); - guid->Data3 = hsSwapEndian16(guid->Data3); + memcpy(dst, src->fData, sizeof(plUUID)); + + // uuid_t struct is big endian, but plUUIDs are always encoded in little endian + // This isn't guaranteed to be 32-bit-aligned, so casting to uint16_t/uint32_t pointers is UB + std::swap(dst[0], dst[3]); + std::swap(dst[1], dst[2]); + std::swap(dst[4], dst[5]); + std::swap(dst[6], dst[7]); } }; diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plBufferedFileReader.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plBufferedFileReader.cpp index f4dd57f3e1..8932537f80 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plBufferedFileReader.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plBufferedFileReader.cpp @@ -113,7 +113,7 @@ void plBufferedFileReader::Close() { //plProfile_DelMem( SndBufferedMem, fBufferSize ); - delete fBuffer; + delete[] fBuffer; fBuffer = nullptr; fBufferSize = 0; fCursor = 0; diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plTransitionMgr.cpp b/Sources/Plasma/PubUtilLib/plPipeline/plTransitionMgr.cpp index 456b90c0a2..5f422693bc 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plTransitionMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/plTransitionMgr.cpp @@ -79,10 +79,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com //// Constructor/Destructor ////////////////////////////////////////////////// plTransitionMgr::plTransitionMgr() + : fEffectPlate(), fCurrentEffect(kIdle), fRegisteredForTime(), + fHoldAtEnd(), fPlaying(), fNoSoundFade(), fEffectLength(), fCurrOpacity(), + fOpacDelta(), fLastTime() { - fEffectPlate = nullptr; - fCurrentEffect = kIdle; - fPlaying = false; } void plTransitionMgr::Init()