From 0b73d3922adb64ce8432de3970e473eece50cf43 Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Sat, 14 Dec 2013 22:59:32 -0800 Subject: [PATCH] - fixed windows build from coverity updates --- source/glest_game/menu/menu_state_custom_game.cpp | 4 ++++ .../sources/feathery_ftp/ftpTargetWin32.c | 3 ++- .../sources/platform/common/platform_common.cpp | 4 ++++ .../shared_lib/sources/platform/posix/ircclient.cpp | 4 ++++ source/shared_lib/sources/platform/posix/socket.cpp | 13 +++++++++++-- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 97d80366..ce4adab9 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -1758,7 +1758,11 @@ void MenuStateCustomGame::PlayNow(bool saveGame) { char szMsg[8096]=""; if(lang.hasString("NetworkSlotUnassignedError",languageList[j]) == true) { string msg_string = lang.getString("NetworkSlotUnassignedError"); +#ifdef WIN32 + strncpy(szMsg,msg_string.c_str(),min((int)msg_string.length(),8095)); +#else strncpy(szMsg,msg_string.c_str(),std::min((int)msg_string.length(),8095)); +#endif } else { strcpy(szMsg,"Cannot start game, some player(s) are not in a network game slot!"); diff --git a/source/shared_lib/sources/feathery_ftp/ftpTargetWin32.c b/source/shared_lib/sources/feathery_ftp/ftpTargetWin32.c index 758cd75c..37ea9877 100644 --- a/source/shared_lib/sources/feathery_ftp/ftpTargetWin32.c +++ b/source/shared_lib/sources/feathery_ftp/ftpTargetWin32.c @@ -425,6 +425,7 @@ socket_t ftpCreateServerSocket(int portNumber) struct sockaddr_in serverinfo; unsigned len; int val = 1; + int opt_result = 0; theServer = socket(AF_INET, SOCK_STREAM, 0); if(theServer == INVALID_SOCKET) @@ -436,7 +437,7 @@ socket_t ftpCreateServerSocket(int portNumber) serverinfo.sin_zero[0] = 0; len = sizeof(serverinfo); - int opt_result = setsockopt(theServer, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)); + opt_result = setsockopt(theServer, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)); if(bind(theServer, (struct sockaddr *)&serverinfo, len)) { if(VERBOSE_MODE_ENABLED) printf("\nERROR In ftpCreateServerSocket bind FAILED about to close listener socket = %d opt_result = %d\n",theServer,opt_result); diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index 269506e8..1f3f84bb 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -2444,7 +2444,11 @@ string safeCharPtrCopy(const char *ptr,int maxLength) { char *pBuffer = new char[maxLength+1]; memset(pBuffer,0,maxLength+1); +#ifdef WIN32 + memcpy(pBuffer,ptr,min((int)strlen(ptr),maxLength)); +#else memcpy(pBuffer,ptr,std::min((int)strlen(ptr),maxLength)); +#endif return pBuffer; } diff --git a/source/shared_lib/sources/platform/posix/ircclient.cpp b/source/shared_lib/sources/platform/posix/ircclient.cpp index 2c5863c6..126c3e96 100644 --- a/source/shared_lib/sources/platform/posix/ircclient.cpp +++ b/source/shared_lib/sources/platform/posix/ircclient.cpp @@ -75,7 +75,11 @@ void dump_event (irc_session_t * session, const char * event, const char * origi if ( cnt ) { strcat (buf, "|"); } +#ifdef WIN32 + strncat (buf, params[cnt],min((int)strlen(params[cnt]),511)); +#else strncat (buf, params[cnt],std::min((int)strlen(params[cnt]),511)); +#endif } addlog ("Event \"%s\", origin: \"%s\", params: %d [%s]", event, origin ? origin : "NULL", cnt, buf); diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index dd1c479c..a306541f 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -2430,8 +2430,13 @@ Socket *ServerSocket::accept(bool errorOnFail) { throwException(szBuf); } else { - ::close(newSock); - newSock = INVALID_SOCKET; + #ifndef WIN32 + ::close(newSock); + newSock = INVALID_SOCKET; + #else + ::closesocket(newSock); + newSock = INVALID_SOCKET; + #endif return NULL; } @@ -2925,7 +2930,11 @@ void BroadCastSocketThread::execute() { strcat(buff,ipList[idx1].c_str()); strcat(buff,":"); string port_string = intToStr(this->boundPort); +#ifdef WIN32 + strncat(buff,port_string.c_str(),min((int)port_string.length(),100)); +#else strncat(buff,port_string.c_str(),std::min((int)port_string.length(),100)); +#endif } if(difftime((long int)time(NULL),elapsed) >= 1 && getQuitStatus() == false) {