From fef6405b6185b08c10d8e4585be2711063728856 Mon Sep 17 00:00:00 2001 From: asmodai Date: Sat, 25 Jul 2015 03:04:18 +0300 Subject: [PATCH] Fixed some issues found by Coverity --- rehlds/engine/hashpak.cpp | 2 +- rehlds/engine/net_ws.cpp | 2 +- rehlds/engine/sv_user.cpp | 18 +++++++++++++++++- rehlds/engine/sv_user.h | 1 + rehlds/public/tier0/platform_win32.cpp | 15 +++++++++++---- rehlds/rehlds/platform.cpp | 9 ++++++++- rehlds/rehlds/platform.h | 2 ++ 7 files changed, 41 insertions(+), 8 deletions(-) diff --git a/rehlds/engine/hashpak.cpp b/rehlds/engine/hashpak.cpp index 4404a42..ad9a45b 100644 --- a/rehlds/engine/hashpak.cpp +++ b/rehlds/engine/hashpak.cpp @@ -821,7 +821,7 @@ void HPAK_CreatePak(char *pakname, struct resource_s *pResource, void *pData, Fi } Q_memset(&hash_pack_header, 0, sizeof(hash_pack_header_t)); - Q_strncpy(hash_pack_header.szFileStamp, "HPAK", sizeof(hash_pack_header.szFileStamp)); + Q_memcpy(hash_pack_header.szFileStamp, "HPAK", sizeof(hash_pack_header.szFileStamp)); hash_pack_header.version = HASHPAK_VERSION; hash_pack_header.nDirectoryOffset = 0; diff --git a/rehlds/engine/net_ws.cpp b/rehlds/engine/net_ws.cpp index 845cc53..92d22ef 100644 --- a/rehlds/engine/net_ws.cpp +++ b/rehlds/engine/net_ws.cpp @@ -889,7 +889,7 @@ qboolean NET_GetLong(unsigned char *pData, int size, int *outSize) Con_Printf("<-- Split packet restart %i count %i seq\n", gNetSplit.splitCount, sequenceNumber); } - int packetPayloadSize = size - sizeof(SPLITPACKET); + unsigned int packetPayloadSize = size - sizeof(SPLITPACKET); if (gNetSplitFlags[packetNumber] == sequenceNumber) { Con_Printf( "NET_GetLong: Ignoring duplicated split packet %i of %i ( %i bytes )\n", diff --git a/rehlds/engine/sv_user.cpp b/rehlds/engine/sv_user.cpp index 2e113b2..3d38267 100644 --- a/rehlds/engine/sv_user.cpp +++ b/rehlds/engine/sv_user.cpp @@ -781,6 +781,9 @@ void SV_RunCmd(usercmd_t *ucmd, int random_seed) sv_player->v.clbasevelocity[1] = 0; sv_player->v.clbasevelocity[2] = 0; sv_player->v.button = ucmd->buttons; +#ifdef REHLDS_FIXES + sv_player->v.light_level = ucmd->lightlevel; +#endif SV_CheckMovingGround(sv_player, frametime); pmove->oldangles[0] = sv_player->v.v_angle[0]; pmove->oldangles[1] = sv_player->v.v_angle[1]; @@ -1498,7 +1501,7 @@ void SV_ParseMove(client_t *pSenderClient) pSenderClient->m_bLoopback = (packetLossByte >> 7) & 1; totalcmds = numcmds + numbackup; net_drop += 1 - numcmds; - if (totalcmds < 0 || totalcmds >= 63) + if (totalcmds < 0 || totalcmds >= CMD_MAXBACKUP - 1) { Con_Printf("SV_ReadClientMessage: too many cmds %i sent for %s/%s\n", totalcmds, host_client->name, NET_AdrToString(host_client->netchan.remote_address)); SV_DropClient(host_client, 0, "CMD_MAXBACKUP hit"); @@ -1534,9 +1537,12 @@ void SV_ParseMove(client_t *pSenderClient) host_client->packet_loss = packet_loss; if (!g_psv.paused && (g_psvs.maxclients > 1 || !key_dest) && !(sv_player->v.flags & FL_FROZEN)) { +#ifndef REHLDS_FIXES + // dup and more correct in SV_RunCmd sv_player->v.v_angle[0] = cmds[0].viewangles[0]; sv_player->v.v_angle[1] = cmds[0].viewangles[1]; sv_player->v.v_angle[2] = cmds[0].viewangles[2]; +#endif } else { @@ -1573,8 +1579,11 @@ void SV_ParseMove(client_t *pSenderClient) } #endif +#ifndef REHLDS_FIXES + // dup and more correct in SV_RunCmd sv_player->v.button = cmds[0].buttons; sv_player->v.light_level = cmds[0].lightlevel; +#endif SV_EstablishTimeBase(host_client, cmds, net_drop, numbackup, numcmds); if (net_drop < 24) { @@ -1597,7 +1606,14 @@ void SV_ParseMove(client_t *pSenderClient) SV_RunCmd(&cmds[i], host_client->netchan.incoming_sequence - i); } +#ifdef REHLDS_FIXES + if (numcmds) + host_client->lastcmd = cmds[numcmds - 1]; + else if (numbackup) + host_client->lastcmd = cmds[0]; +#else host_client->lastcmd = cmds[0]; +#endif frame->ping_time -= float(host_client->lastcmd.msec * 0.5 / 1000.0); if (frame->ping_time < 0.0) diff --git a/rehlds/engine/sv_user.h b/rehlds/engine/sv_user.h index 513db86..44fc49f 100644 --- a/rehlds/engine/sv_user.h +++ b/rehlds/engine/sv_user.h @@ -37,6 +37,7 @@ #include "world.h" #include "pm_defs.h" +#define CMD_MAXBACKUP 64 typedef struct command_s command_t; diff --git a/rehlds/public/tier0/platform_win32.cpp b/rehlds/public/tier0/platform_win32.cpp index 10562ee..26b53a5 100644 --- a/rehlds/public/tier0/platform_win32.cpp +++ b/rehlds/public/tier0/platform_win32.cpp @@ -10,6 +10,7 @@ static LARGE_INTEGER g_PerformanceFrequency; static LARGE_INTEGER g_MSPerformanceFrequency; static LARGE_INTEGER g_ClockStart; +static HINSTANCE g_pVTuneDLL; static void InitTime() { @@ -45,6 +46,11 @@ unsigned long Plat_MSTime() return (unsigned long)((CurrentTime.QuadPart - g_ClockStart.QuadPart) / g_MSPerformanceFrequency.QuadPart); } +void free_vtune() +{ + FreeLibrary(g_pVTuneDLL); +} + bool vtune(bool resume) { static bool bInitialized = false; @@ -56,12 +62,13 @@ bool vtune(bool resume) { bInitialized = true; - HINSTANCE pVTuneDLL = LoadLibrary("vtuneapi.dll"); + g_pVTuneDLL = LoadLibrary("vtuneapi.dll"); - if (pVTuneDLL) + if (g_pVTuneDLL) { - VTResume = (void(__cdecl *)())GetProcAddress(pVTuneDLL, "VTResume"); - VTPause = (void(__cdecl *)())GetProcAddress(pVTuneDLL, "VTPause"); + VTResume = (void(__cdecl *)())GetProcAddress(g_pVTuneDLL, "VTResume"); + VTPause = (void(__cdecl *)())GetProcAddress(g_pVTuneDLL, "VTPause"); + atexit(free_vtune); } } diff --git a/rehlds/rehlds/platform.cpp b/rehlds/rehlds/platform.cpp index 1d01106..19b10ed 100644 --- a/rehlds/rehlds/platform.cpp +++ b/rehlds/rehlds/platform.cpp @@ -16,13 +16,20 @@ void CRehldsPlatformHolder::set(IReHLDSPlatform* p) { CSimplePlatform::CSimplePlatform() { #ifdef _WIN32 - HMODULE wsock = LoadLibraryA("wsock32.dll"); + wsock = LoadLibraryA("wsock32.dll"); setsockopt_v11 = (setsockopt_proto)GetProcAddress(wsock, "setsockopt"); if (setsockopt_v11 == NULL) rehlds_syserror("%s: setsockopt_v11 not found", __FUNCTION__); #endif } +CSimplePlatform::~CSimplePlatform() +{ +#ifdef _WIN32 + FreeLibrary(wsock); +#endif +} + uint32 CSimplePlatform::time(uint32* pTime) { time_t res = ::time((time_t*)NULL); diff --git a/rehlds/rehlds/platform.h b/rehlds/rehlds/platform.h index d9543dc..befc59f 100644 --- a/rehlds/rehlds/platform.h +++ b/rehlds/rehlds/platform.h @@ -60,10 +60,12 @@ class CSimplePlatform : public IReHLDSPlatform { private: #ifdef _WIN32 setsockopt_proto setsockopt_v11; + HMODULE wsock; #endif public: CSimplePlatform(); + virtual ~CSimplePlatform(); virtual uint32 time(uint32* pTime); virtual struct tm* localtime(uint32 time);