From c7bee037d2c06c56893d631651288c33e3cb95ae Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 1 May 2023 14:44:52 +0300 Subject: [PATCH] Fix potential nullptr-to-reference conversion --- server/CVCMIServer.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 1c95a2c3e..9835cb215 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -375,10 +375,10 @@ class CVCMIServerPackVisitor : public VCMI_LIB_WRAP_NAMESPACE(ICPackVisitor) { private: CVCMIServer & handler; - CGameHandler & gh; + std::shared_ptr gh; public: - CVCMIServerPackVisitor(CVCMIServer & handler, CGameHandler & gh) + CVCMIServerPackVisitor(CVCMIServer & handler, std::shared_ptr gh) :handler(handler), gh(gh) { } @@ -392,7 +392,10 @@ public: virtual void visitForServer(CPackForServer & serverPack) override { - gh.handleReceivedPack(&serverPack); + if (gh) + gh->handleReceivedPack(&serverPack); + else + logNetwork->error("Received pack for game server while in lobby!"); } virtual void visitForClient(CPackForClient & clientPack) override @@ -432,7 +435,7 @@ void CVCMIServer::threadHandleClient(std::shared_ptr c) break; } - CVCMIServerPackVisitor visitor(*this, *this->gh); + CVCMIServerPackVisitor visitor(*this, this->gh); pack->visit(visitor); } #ifndef _MSC_VER