1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Merge pull request #2109 from IvanSavenko/server_fix

Fix potential nullptr-to-reference conversion
This commit is contained in:
Ivan Savenko
2023-05-01 16:36:51 +03:00
committed by GitHub

View File

@@ -375,10 +375,10 @@ class CVCMIServerPackVisitor : public VCMI_LIB_WRAP_NAMESPACE(ICPackVisitor)
{ {
private: private:
CVCMIServer & handler; CVCMIServer & handler;
CGameHandler & gh; std::shared_ptr<CGameHandler> gh;
public: public:
CVCMIServerPackVisitor(CVCMIServer & handler, CGameHandler & gh) CVCMIServerPackVisitor(CVCMIServer & handler, std::shared_ptr<CGameHandler> gh)
:handler(handler), gh(gh) :handler(handler), gh(gh)
{ {
} }
@@ -392,7 +392,10 @@ public:
virtual void visitForServer(CPackForServer & serverPack) override 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 virtual void visitForClient(CPackForClient & clientPack) override
@@ -432,7 +435,7 @@ void CVCMIServer::threadHandleClient(std::shared_ptr<CConnection> c)
break; break;
} }
CVCMIServerPackVisitor visitor(*this, *this->gh); CVCMIServerPackVisitor visitor(*this, this->gh);
pack->visit(visitor); pack->visit(visitor);
} }
#ifndef _MSC_VER #ifndef _MSC_VER