2
0
mirror of https://github.com/rehlds/rehlds.git synced 2025-01-01 01:25:38 +03:00

Fixed some issues found by Coverity

This commit is contained in:
asmodai 2015-07-25 03:04:18 +03:00
parent 8d73400168
commit fef6405b61
7 changed files with 41 additions and 8 deletions

View File

@ -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;

View File

@ -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",

View File

@ -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)

View File

@ -37,6 +37,7 @@
#include "world.h"
#include "pm_defs.h"
#define CMD_MAXBACKUP 64
typedef struct command_s command_t;

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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);