Преглед изворни кода

Fix crash due to passing args

nordsoft пре 2 година
родитељ
комит
694fedc662
4 измењених фајлова са 6 додато и 9 уклоњено
  1. 4 6
      launcher/main.cpp
  2. 0 2
      launcher/main.h
  3. 1 1
      server/CVCMIServer.cpp
  4. 1 0
      server/CVCMIServer.h

+ 4 - 6
launcher/main.cpp

@@ -29,8 +29,6 @@ int main(int argc, char * argv[])
 {
 	int result;
 #ifdef VCMI_IOS
-	argcForClient = argc;
-	argvForClient = argv;
 	{
 #endif
 	QApplication vcmilauncher(argc, argv);
@@ -51,13 +49,13 @@ void startGame(const QStringList & args)
 
 #ifdef Q_OS_IOS
 	argcForClient = args.size() + 1; //first argument is omitted
-	argvForClient = new char*[argcForClient];
+    argvForClient = new char*[argcForClient];
 	argvForClient[0] = "vcmiclient";
 	for(int i = 1; i < argcForClient; ++i)
 	{
-		const char * s = args[i - 1].toLocal8Bit().constData();
-		argvForClient[i] = new char[strlen(s)];
-		strcpy(argvForClient[i], s);
+        std::string s = args.at(i - 1).toStdString();
+        argvForClient[i] = new char[s.size() + 1];
+        strcpy(argvForClient[i], s.c_str());
 	}
 	qApp->quit();
 #else

+ 0 - 2
launcher/main.h

@@ -12,8 +12,6 @@
 void startGame(const QStringList & args);
 
 #ifdef VCMI_IOS
-extern int argcForClient;
-extern char** argvForClient;
 extern "C" void launchGame(int argc, char * argv[]);
 #else
 void startExecutable(QString name, const QStringList & args);

+ 1 - 1
server/CVCMIServer.cpp

@@ -207,7 +207,7 @@ void CVCMIServer::establishRemoteConnections()
 	int port = cmdLineOptions["lobby-port"].as<ui16>();
 	logGlobal->info("Server is connecting to remote at %s:%d with uuid %d times", address, port, uuid, numOfConnections);
 	
-	for(int i = 0; i < numOfConnections; ++i)
+	for(int i = 0; i < numOfConnections && i == remotePipeConnections; ++i, ++remotePipeConnections)
 		connectToRemote(address, port);
 }
 

+ 1 - 0
server/CVCMIServer.h

@@ -53,6 +53,7 @@ class CVCMIServer : public LobbyInfo
 	boost::recursive_mutex mx;
 	std::shared_ptr<CApplier<CBaseForServerApply>> applier;
 	std::unique_ptr<boost::thread> announceLobbyThread, remoteConnectionsThread;
+    int remotePipeConnections = 0;
 
 public:
 	std::shared_ptr<CGameHandler> gh;