diff --git a/src/common/IPC/Primitives.cpp b/src/common/IPC/Primitives.cpp index 14bdd8c339..bdc74e3193 100644 --- a/src/common/IPC/Primitives.cpp +++ b/src/common/IPC/Primitives.cpp @@ -234,7 +234,8 @@ static void InternalSendMsg(Sys::OSHandle handle, bool more, const FileDesc* han } #else size_t descBytes = 0; - std::unique_ptr descBuffer; + static std::unique_ptr descBuffer; + static size_t descBufferSize = 0; if (numHandles != 0) { for (size_t i = 0; i < numHandles; i++) { // tag: 1 byte @@ -250,7 +251,10 @@ static void InternalSendMsg(Sys::OSHandle handle, bool more, const FileDesc* han // Add 1 byte end tag and round to 16 bytes descBytes = (descBytes + 1 + 0xf) & ~0xf; - descBuffer.reset(new unsigned char[descBytes]); + if (descBufferSize < descBytes) { + descBufferSize = descBytes; + descBuffer.reset(new unsigned char[descBytes]); + } unsigned char* descBuffer_ptr = &descBuffer[0]; for (size_t i = 0; i < numHandles; i++) { *descBuffer_ptr++ = handles[i].type; @@ -336,11 +340,15 @@ bool InternalRecvMsg(Sys::OSHandle handle, Util::Reader& reader) NaClIOVec iov[2]; NaClHandle h[NACL_ABI_IMC_DESC_MAX]; if (!recvBuffer) { - recvBuffer.reset(new char[NACL_ABI_IMC_BYTES_MAX]); + //while using malloc in combination with delete[] or delete is + //a bad idea in theory, in this case, we are freeing an array of + //bytes, there is NOTHING special to clean in a string of bytes. + //This does, however, avoid new[] or new to initilialise data, + //those functions being actually closer to calloc than malloc. + recvBuffer.reset( static_cast( malloc( NACL_ABI_IMC_BYTES_MAX ) ) ); } - for (size_t i = 0; i < NACL_ABI_IMC_DESC_MAX; i++) - h[i] = NACL_INVALID_HANDLE; + std::fill(std::begin(h), std::end(h),NACL_INVALID_HANDLE) #ifdef __native_client__ hdr.iov = iov; @@ -361,6 +369,8 @@ bool InternalRecvMsg(Sys::OSHandle handle, Util::Reader& reader) if (hdr.flags & (NACL_MESSAGE_TRUNCATED | NACL_HANDLES_TRUNCATED)) Sys::Drop("IPC: Recieved truncated message"); + // NACL_ABI_IMC_DESC_MAX == 8 anyway, so let's avoid useless loops and reallocs + reader.GetHandles().reserve(reader.GetHandles().size() + NACL_ABI_IMC_DESC_MAX); for (size_t i = 0; i < NACL_ABI_IMC_DESC_MAX; i++) { if (h[i] != NACL_INVALID_HANDLE) { reader.GetHandles().emplace_back(); diff --git a/src/common/Serialize.h b/src/common/Serialize.h index 6e71639e76..3ef6f0389c 100644 --- a/src/common/Serialize.h +++ b/src/common/Serialize.h @@ -80,7 +80,7 @@ namespace Util { { if (size > std::numeric_limits::max()) Sys::Drop("IPC: Size out of range in message"); - Write(size); + Write(static_cast( size )); } template void Write(Arg&& value) { @@ -130,10 +130,16 @@ namespace Util { public: Reader() : pos(0), handles_pos(0) {} + Reader(Reader const& other) = delete; + Reader& operator=(Reader const& other) = delete; Reader(Reader&& other) NOEXCEPT : data(std::move(other.data)), handles(std::move(other.handles)), pos(other.pos), handles_pos(other.handles_pos) {} Reader& operator=(Reader&& other) NOEXCEPT { + if (this == &other) + { + return *this; + } std::swap(data, other.data); std::swap(handles, other.handles); std::swap(pos, other.pos); @@ -143,8 +149,8 @@ namespace Util { ~Reader() { // Close any handles that weren't read - for (size_t i = handles_pos; i < handles.size(); i++) - handles[i].Close(); + for (auto it = handles.begin() + handles_pos; it != handles.end(); ++it) + it->Close(); } void ReadData(void* p, size_t len) @@ -247,7 +253,7 @@ namespace Util { struct SerializeTraits { static void Write(Writer& stream, bool value) { - stream.Write(+value); + stream.Write(static_cast(value)); } static bool Read(Reader& stream) { diff --git a/src/engine/renderer/tr_local.h b/src/engine/renderer/tr_local.h index eab633f98f..cb9619f3e3 100644 --- a/src/engine/renderer/tr_local.h +++ b/src/engine/renderer/tr_local.h @@ -3843,23 +3843,23 @@ void GLimp_LogComment_( std::string comment ); virtual const RenderCommand *ExecuteSelf() const = 0; }; - struct SetColorCommand : public RenderCommand { + struct SetColorCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; Color::Color color; }; - struct SetColorGradingCommand : public RenderCommand { + struct SetColorGradingCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; image_t *image; int slot; }; - struct DrawBufferCommand : public RenderCommand { + struct DrawBufferCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; int buffer; }; - struct SwapBuffersCommand : public RenderCommand { + struct SwapBuffersCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; }; struct StretchPicCommand : public RenderCommand { @@ -3871,25 +3871,25 @@ void GLimp_LogComment_( std::string comment ); float s1, t1; float s2, t2; }; - struct RotatedPicCommand : public StretchPicCommand { + struct RotatedPicCommand final : public StretchPicCommand { const RenderCommand *ExecuteSelf() const override; float angle; }; - struct GradientPicCommand : public StretchPicCommand { + struct GradientPicCommand final : public StretchPicCommand { const RenderCommand *ExecuteSelf() const override; Color::Color32Bit gradientColor; // color values 0-255 int gradientType; }; - struct Poly2dCommand : public RenderCommand { + struct Poly2dCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; polyVert_t *verts; int numverts; shader_t *shader; }; - struct Poly2dIndexedCommand : public RenderCommand { + struct Poly2dIndexedCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; polyVert_t *verts; @@ -3899,7 +3899,7 @@ void GLimp_LogComment_( std::string comment ); shader_t *shader; int translation[2]; }; - struct ScissorSetCommand : public RenderCommand { + struct ScissorSetCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; int x; @@ -3907,22 +3907,22 @@ void GLimp_LogComment_( std::string comment ); int w; int h; }; - struct SetMatrixTransformCommand : public RenderCommand { + struct SetMatrixTransformCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; matrix_t matrix; }; - struct ResetMatrixTransformCommand : public RenderCommand { + struct ResetMatrixTransformCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; }; - struct DrawViewCommand : public RenderCommand { + struct DrawViewCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; trRefdef_t refdef; viewParms_t viewParms; bool depthPass; }; - struct SetupLightsCommand : public RenderCommand { + struct SetupLightsCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; trRefdef_t refdef; @@ -3933,7 +3933,7 @@ void GLimp_LogComment_( std::string comment ); SSF_JPEG, SSF_PNG }; - struct ScreenshotCommand : public RenderCommand { + struct ScreenshotCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; int x; @@ -3943,7 +3943,7 @@ void GLimp_LogComment_( std::string comment ); char fileName[MAX_OSPATH]; ssFormat_t format; }; - struct VideoFrameCommand : public RenderCommand { + struct VideoFrameCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; int width; @@ -3952,33 +3952,33 @@ void GLimp_LogComment_( std::string comment ); byte *encodeBuffer; bool motionJpeg; }; - struct RenderPostProcessCommand : public RenderCommand { + struct RenderPostProcessCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; trRefdef_t refdef; viewParms_t viewParms; }; - struct ClearBufferCommand : public RenderCommand { + struct ClearBufferCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; trRefdef_t refdef; viewParms_t viewParms; }; - struct PreparePortalCommand : public RenderCommand { + struct PreparePortalCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; trRefdef_t refdef; viewParms_t viewParms; drawSurf_t *surface; }; - struct FinalisePortalCommand : public RenderCommand { + struct FinalisePortalCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; trRefdef_t refdef; viewParms_t viewParms; drawSurf_t *surface; }; - struct EndOfListCommand : public RenderCommand { + struct EndOfListCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; };