fixed some coverity warnings

This commit is contained in:
jeefo 2015-06-29 20:51:25 +03:00
commit 95c121ef43
10 changed files with 127 additions and 56 deletions

View file

@ -148,12 +148,18 @@ public:
{ {
m_textSize = 0; m_textSize = 0;
m_codeSize = 0; m_codeSize = 0;
m_matchPosition = 0;
m_matchLength = 0;
} }
~Compressor (void) ~Compressor (void)
{ {
m_textSize = 0; m_textSize = 0;
m_codeSize = 0; m_codeSize = 0;
m_matchPosition = 0;
m_matchLength = 0;
} }
int InternalEncode (const char *fileName, byte *header, int headerSize, byte *buffer, int bufferSize) int InternalEncode (const char *fileName, byte *header, int headerSize, byte *buffer, int bufferSize)

View file

@ -110,14 +110,12 @@ public:
Library (const char *fileName) Library (const char *fileName)
{ {
m_ptr = NULL;
if (fileName == NULL) if (fileName == NULL)
return; return;
#ifdef PLATFORM_WIN32 LoadLib (fileName);
m_ptr = LoadLibrary (fileName);
#else
m_ptr = dlopen (fileName, RTLD_NOW);
#endif
} }
~Library (void) ~Library (void)
@ -133,6 +131,16 @@ public:
} }
public: public:
inline void *LoadLib (const char *fileName)
{
#ifdef PLATFORM_WIN32
m_ptr = LoadLibrary (fileName);
#else
m_ptr = dlopen (fileName, RTLD_NOW);
#endif
return m_ptr;
}
void *GetFunctionAddr (const char *functionName) void *GetFunctionAddr (const char *functionName)
{ {
if (!IsLoaded ()) if (!IsLoaded ())
@ -1050,7 +1058,7 @@ private:
void RunPlayerMovement (void); void RunPlayerMovement (void);
byte ThrottledMsec (void); byte ThrottledMsec (void);
void GetValidWaypoint (void); void GetValidWaypoint (void);
void ChangeWptIndex (int waypointIndex); int ChangeWptIndex (int waypointIndex);
bool IsDeadlyDrop (const Vector &to); bool IsDeadlyDrop (const Vector &to);
bool OutOfBombTimer (void); bool OutOfBombTimer (void);
void SelectLeaderEachTeam (int team); void SelectLeaderEachTeam (int team);
@ -1580,6 +1588,8 @@ public:
public: public:
ConVar (const char *name, const char *initval, VarType type = VT_NORMAL) ConVar (const char *name, const char *initval, VarType type = VT_NORMAL)
{ {
m_eptr = NULL;
g_convarWrapper->RegisterVariable (name, initval, type, this); g_convarWrapper->RegisterVariable (name, initval, type, this);
} }

View file

@ -1406,7 +1406,6 @@ void Bot::CheckMessageQueue (void)
TeamSayText (m_tempStrings); TeamSayText (m_tempStrings);
break; break;
case GSM_IDLE:
default: default:
return; return;
} }
@ -5196,7 +5195,7 @@ void Bot::BotAI (void)
} }
} }
else else
strcpy (weaponName, selectTab->weaponName); strncpy (weaponName, selectTab->weaponName, sizeof (weaponName));
char outputBuffer[512]; char outputBuffer[512];
memset (outputBuffer, 0, sizeof (outputBuffer)); memset (outputBuffer, 0, sizeof (outputBuffer));
@ -5961,12 +5960,22 @@ void Bot::ReactOnSound (void)
float maxVolume = 0.0, volume = 0.0; float maxVolume = 0.0, volume = 0.0;
int hearEnemyIndex = -1; int hearEnemyIndex = -1;
Vector testHearing = EyePosition ();
if (pev->flags & FL_DUCKING)
testHearing += VEC_HULL_MIN - VEC_DUCK_HULL_MIN;
unsigned char *pas = ENGINE_SET_PAS ((reinterpret_cast <float *> (&testHearing)));
// loop through all enemy clients to check for hearable stuff // loop through all enemy clients to check for hearable stuff
for (int i = 0; i < GetMaxClients (); i++) for (int i = 0; i < GetMaxClients (); i++)
{ {
if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE) || g_clients[i].ent == GetEntity () || g_clients[i].timeSoundLasting < GetWorldTime ()) if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE) || g_clients[i].ent == GetEntity () || g_clients[i].timeSoundLasting < GetWorldTime ())
continue; continue;
if (!ENGINE_CHECK_VISIBILITY (g_clients[i].ent, pas))
continue;
float distance = (g_clients[i].soundPosition - pev->origin).GetLength (); float distance = (g_clients[i].soundPosition - pev->origin).GetLength ();
float hearingDistance = g_clients[i].hearingDistance; float hearingDistance = g_clients[i].hearingDistance;
@ -5981,7 +5990,7 @@ void Bot::ReactOnSound (void)
else else
volume = 2.0 * hearingDistance * (1.0 - distance / hearingDistance) * (g_clients[i].timeSoundLasting - GetWorldTime ()) / g_clients[i].maxTimeSoundLasting; volume = 2.0 * hearingDistance * (1.0 - distance / hearingDistance) * (g_clients[i].timeSoundLasting - GetWorldTime ()) / g_clients[i].maxTimeSoundLasting;
if (g_clients[hearEnemyIndex].team == m_team && yb_csdm_mode.GetInt () != 2) if (g_clients[i].team == m_team && yb_csdm_mode.GetInt () != 2)
volume = 0.3 * volume; volume = 0.3 * volume;
// we will care about the most hearable sound instead of the closest one - KWo // we will care about the most hearable sound instead of the closest one - KWo

View file

@ -88,8 +88,8 @@ char *HumanizeName (char *name)
{ {
// this function humanize player name (i.e. trim clan and switch to lower case (sometimes)) // this function humanize player name (i.e. trim clan and switch to lower case (sometimes))
static char outputName[256]; // create return name buffer static char outputName[64]; // create return name buffer
strcpy (outputName, name); // copy name to new buffer strncpy (outputName, name, sizeof (outputName)); // copy name to new buffer
// drop tag marks, 80 percent of time // drop tag marks, 80 percent of time
if (Random.Long (1, 100) < 80) if (Random.Long (1, 100) < 80)
@ -199,7 +199,7 @@ void Bot::PrepareChatMessage (char *text)
talkEntity = g_clients[index].ent; talkEntity = g_clients[index].ent;
if (!IsEntityNull (talkEntity)) if (!IsEntityNull (talkEntity))
strcat (m_tempStrings, HumanizeName (const_cast <char *> (STRING (talkEntity->v.netname)))); strncat (m_tempStrings, HumanizeName (const_cast <char *> (STRING (talkEntity->v.netname))), sizeof (m_tempStrings));
} }
// mapname? // mapname?
else if (*pattern == 'm') else if (*pattern == 'm')
@ -216,7 +216,7 @@ void Bot::PrepareChatMessage (char *text)
talkEntity = EntityOfIndex (m_sayTextBuffer.entityIndex); talkEntity = EntityOfIndex (m_sayTextBuffer.entityIndex);
if (!IsEntityNull (talkEntity)) if (!IsEntityNull (talkEntity))
strcat (m_tempStrings, HumanizeName (const_cast <char *> (STRING (talkEntity->v.netname)))); strncat (m_tempStrings, HumanizeName (const_cast <char *> (STRING (talkEntity->v.netname))), sizeof (m_tempStrings));
} }
// teammate alive? // teammate alive?
else if (*pattern == 't') else if (*pattern == 't')
@ -239,7 +239,7 @@ void Bot::PrepareChatMessage (char *text)
talkEntity = g_clients[i].ent; talkEntity = g_clients[i].ent;
if (!IsEntityNull (talkEntity)) if (!IsEntityNull (talkEntity))
strcat (m_tempStrings, HumanizeName (const_cast <char *> (STRING (talkEntity->v.netname)))); strncat (m_tempStrings, HumanizeName (const_cast <char *> (STRING (talkEntity->v.netname))), sizeof (m_tempStrings));
} }
else // no teammates alive... else // no teammates alive...
{ {
@ -256,7 +256,7 @@ void Bot::PrepareChatMessage (char *text)
talkEntity = g_clients[i].ent; talkEntity = g_clients[i].ent;
if (!IsEntityNull (talkEntity)) if (!IsEntityNull (talkEntity))
strcat (m_tempStrings, HumanizeName (const_cast <char *> (STRING (talkEntity->v.netname)))); strncat (m_tempStrings, HumanizeName (const_cast <char *> (STRING (talkEntity->v.netname))), sizeof (m_tempStrings));
} }
} }
} }
@ -276,7 +276,7 @@ void Bot::PrepareChatMessage (char *text)
talkEntity = g_clients[i].ent; talkEntity = g_clients[i].ent;
if (!IsEntityNull (talkEntity)) if (!IsEntityNull (talkEntity))
strcat (m_tempStrings, HumanizeName (const_cast <char *> (STRING (talkEntity->v.netname)))); strncat (m_tempStrings, HumanizeName (const_cast <char *> (STRING (talkEntity->v.netname))), sizeof (m_tempStrings));
} }
else // no teammates alive... else // no teammates alive...
{ {
@ -291,7 +291,7 @@ void Bot::PrepareChatMessage (char *text)
talkEntity = g_clients[i].ent; talkEntity = g_clients[i].ent;
if (!IsEntityNull (talkEntity)) if (!IsEntityNull (talkEntity))
strcat (m_tempStrings, HumanizeName (const_cast <char *> (STRING (talkEntity->v.netname)))); strncat (m_tempStrings, HumanizeName (const_cast <char *> (STRING (talkEntity->v.netname))), sizeof (m_tempStrings));
} }
} }
} }
@ -317,7 +317,7 @@ void Bot::PrepareChatMessage (char *text)
talkEntity = m_lastVictim; talkEntity = m_lastVictim;
if (!IsEntityNull (talkEntity)) if (!IsEntityNull (talkEntity))
strcat (m_tempStrings, HumanizeName (const_cast <char *> (STRING (talkEntity->v.netname)))); strncat (m_tempStrings, HumanizeName (const_cast <char *> (STRING (talkEntity->v.netname))), sizeof (m_tempStrings));
} }
pattern++; pattern++;
textStart = pattern; textStart = pattern;

View file

@ -516,7 +516,7 @@ void InitConfig (void)
while (fp.GetBuffer (line, 255)) while (fp.GetBuffer (line, 255))
{ {
SKIP_COMMENTS (); SKIP_COMMENTS ();
strcpy (section, GetField (line, 0, 1)); strncpy (section, GetField (line, 0, 1), sizeof (section));
if (strcmp (section, "[KILLED]") == 0) if (strcmp (section, "[KILLED]") == 0)
{ {
@ -1988,13 +1988,13 @@ void ClientCommand (edict_t *ent)
if (target != NULL) if (target != NULL)
{ {
target->m_sayTextBuffer.entityIndex = IndexOfEntity (ent); target->m_sayTextBuffer.entityIndex = IndexOfEntity (ent);
if (IsNullString (CMD_ARGS ())) if (IsNullString (CMD_ARGS ()))
continue; continue;
strcpy (target->m_sayTextBuffer.sayText, CMD_ARGS ()); strncpy (target->m_sayTextBuffer.sayText, CMD_ARGS (), sizeof (target->m_sayTextBuffer.sayText));
target->m_sayTextBuffer.timeNextChat = GetWorldTime () + target->m_sayTextBuffer.chatDelay; target->m_sayTextBuffer.timeNextChat = GetWorldTime () + target->m_sayTextBuffer.chatDelay;
} }
} }
} }
@ -3114,7 +3114,7 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t
); );
g_gameLib = new Library (gameDLLName); g_gameLib = new Library (gameDLLName);
if (!g_gameLib->IsLoaded()) if (!g_gameLib->IsLoaded ())
{ {
// try to extract the game dll out of the steam cache // try to extract the game dll out of the steam cache
AddLogEntry (true, LL_WARNING | LL_IGNORE, "Trying to extract dll '%s' out of the steam cache", gameDLLName); AddLogEntry (true, LL_WARNING | LL_IGNORE, "Trying to extract dll '%s' out of the steam cache", gameDLLName);
@ -3135,7 +3135,10 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t
} }
FREE_FILE (buffer); FREE_FILE (buffer);
} }
g_gameLib = new Library (gameDLLName); g_gameLib->LoadLib (gameDLLName);
if (!g_gameLib->IsLoaded ())
AddLogEntry (true, LL_FATAL | LL_IGNORE, "Unable to load gamedll \"%s\". Exiting... (gamedir: %s)", gameDLLName, GetModName ());
} }
} }
else else

View file

@ -36,8 +36,8 @@ BotManager::BotManager (void)
memset (m_bots, 0, sizeof (m_bots)); memset (m_bots, 0, sizeof (m_bots));
if (g_pGlobals != NULL) m_maintainTime = 0.0f;
InitQuota (); m_creationTab.RemoveAll ();
} }
BotManager::~BotManager (void) BotManager::~BotManager (void)
@ -131,7 +131,7 @@ int BotManager::CreateBot (const String &name, int difficulty, int personality,
continue; continue;
pickedName->used = nameFound = true; pickedName->used = nameFound = true;
strcpy (outputName, pickedName->name); strncpy (outputName, pickedName->name, sizeof (outputName));
steamId = pickedName->steamId; steamId = pickedName->steamId;
} }
@ -167,7 +167,7 @@ int BotManager::CreateBot (const String &name, int difficulty, int personality,
m_bots[index] = new Bot (bot, difficulty, personality, team, member, steamId); m_bots[index] = new Bot (bot, difficulty, personality, team, member, steamId);
if (m_bots == NULL) if (m_bots[index] == NULL)
TerminateOnMalloc (); TerminateOnMalloc ();
ServerPrint ("Connecting Bot..."); ServerPrint ("Connecting Bot...");

View file

@ -224,7 +224,7 @@ TacticChoosen:
} }
if (m_currentWaypointIndex == -1 || m_currentWaypointIndex >= g_numWaypoints) if (m_currentWaypointIndex == -1 || m_currentWaypointIndex >= g_numWaypoints)
ChangeWptIndex (g_waypoint->FindNearest (pev->origin)); m_currentWaypointIndex = ChangeWptIndex (g_waypoint->FindNearest (pev->origin));
if (goalChoices[0] == -1) if (goalChoices[0] == -1)
return m_chosenGoalIndex = Random.Long (0, g_numWaypoints - 1); return m_chosenGoalIndex = Random.Long (0, g_numWaypoints - 1);
@ -410,11 +410,11 @@ void Bot::CheckTerrain (float movedDistance, const Vector &dir, const Vector &di
int bits = 0; int bits = 0;
if (IsOnLadder ()) if (IsOnLadder ())
bits = PROBE_STRAFE; bits |= PROBE_STRAFE;
else if (IsInWater ()) else if (IsInWater ())
bits = (PROBE_JUMP | PROBE_STRAFE); bits |= (PROBE_JUMP | PROBE_STRAFE);
else else
bits = ((Random.Long (0, 10) > (cantMoveForward ? 7 : 5) ? PROBE_JUMP : 0) | PROBE_STRAFE | PROBE_DUCK); bits |= ((Random.Long (0, 10) > (cantMoveForward ? 7 : 5) ? PROBE_JUMP : 0) | PROBE_STRAFE | PROBE_DUCK);
// collision check allowed if not flying through the air // collision check allowed if not flying through the air
if (IsOnFloor () || IsOnLadder () || IsInWater ()) if (IsOnFloor () || IsOnLadder () || IsInWater ())
@ -553,7 +553,6 @@ void Bot::CheckTerrain (float movedDistance, const Vector &dir, const Vector &di
{ {
state[i] = 0; state[i] = 0;
i++; i++;
state[i] = 0; state[i] = 0;
} }
@ -1275,7 +1274,7 @@ public:
inline ~PriorityQueue (void) inline ~PriorityQueue (void)
{ {
delete[] m_heap; free (m_heap);
m_heap = NULL; m_heap = NULL;
} }
@ -1662,6 +1661,7 @@ void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType)
break; break;
} }
// put start node into open list // put start node into open list
astar[srcIndex].g = gcalc (srcIndex, -1); astar[srcIndex].g = gcalc (srcIndex, -1);
astar[srcIndex].f = astar[srcIndex].g + hcalc (srcIndex, srcIndex, destIndex); astar[srcIndex].f = astar[srcIndex].g + hcalc (srcIndex, srcIndex, destIndex);
@ -1753,7 +1753,7 @@ int Bot::GetAimingWaypoint (const Vector &to)
// return the most distant waypoint which is seen from the Bot to the Target and is within count // return the most distant waypoint which is seen from the Bot to the Target and is within count
if (m_currentWaypointIndex == -1) if (m_currentWaypointIndex == -1)
ChangeWptIndex (g_waypoint->FindNearest (pev->origin)); m_currentWaypointIndex = ChangeWptIndex (g_waypoint->FindNearest (pev->origin));
int srcIndex = m_currentWaypointIndex; int srcIndex = m_currentWaypointIndex;
int destIndex = g_waypoint->FindNearest (to); int destIndex = g_waypoint->FindNearest (to);
@ -1996,10 +1996,10 @@ void Bot::GetValidWaypoint (void)
} }
} }
void Bot::ChangeWptIndex (int waypointIndex) int Bot::ChangeWptIndex(int waypointIndex)
{ {
if (waypointIndex == -1) if (waypointIndex == -1)
return; return 0;
m_prevWptIndex[4] = m_prevWptIndex[3]; m_prevWptIndex[4] = m_prevWptIndex[3];
m_prevWptIndex[3] = m_prevWptIndex[2]; m_prevWptIndex[3] = m_prevWptIndex[2];
@ -2011,6 +2011,8 @@ void Bot::ChangeWptIndex (int waypointIndex)
m_currentPath = g_waypoint->GetPath (m_currentWaypointIndex); m_currentPath = g_waypoint->GetPath (m_currentWaypointIndex);
m_waypointFlags = m_currentPath->flags; m_waypointFlags = m_currentPath->flags;
return m_currentWaypointIndex; // to satisfy static-code analyzers
} }
int Bot::ChooseBombWaypoint (void) int Bot::ChooseBombWaypoint (void)
@ -3066,6 +3068,9 @@ int Bot::GetAimingWaypoint (void)
int currentWaypoint = g_waypoint->FindNearest (pev->origin); int currentWaypoint = g_waypoint->FindNearest (pev->origin);
if (currentWaypoint == -1)
return Random.Long (0, g_numWaypoints - 1);
for (int i = 0; i < g_numWaypoints; i++) for (int i = 0; i < g_numWaypoints; i++)
{ {
if (currentWaypoint == i || !g_waypoint->IsVisible (currentWaypoint, i)) if (currentWaypoint == i || !g_waypoint->IsVisible (currentWaypoint, i))

View file

@ -95,7 +95,7 @@ void NetworkMsg::Execute (void *p)
switch (m_state) switch (m_state)
{ {
case 0: case 0:
strcpy (weaponProp.className, PTR_TO_STR (p)); strncpy (weaponProp.className, PTR_TO_STR (p), sizeof (weaponProp.className));
break; break;
case 1: case 1:

View file

@ -941,7 +941,7 @@ const char *GetMapName (void)
// this function gets the map name and store it in the map_name global string variable. // this function gets the map name and store it in the map_name global string variable.
static char mapName[256]; static char mapName[256];
strcpy (mapName, const_cast <const char *> (g_pGlobals->pStringBase + static_cast <int> (g_pGlobals->mapname))); strncpy (mapName, const_cast <const char *> (g_pGlobals->pStringBase + static_cast <int> (g_pGlobals->mapname)), sizeof (mapName));
return &mapName[0]; // and return a pointer to it return &mapName[0]; // and return a pointer to it
} }
@ -1118,10 +1118,11 @@ float GetWaveLength (const char *fileName)
return 0; return 0;
} }
// whoa, what a shit, is this working ?!
char ch[32]; char ch[32];
sprintf (ch, "0.%u", static_cast <unsigned int> (waveHdr.dataChunkLength)); sprintf (ch, "0.%u", static_cast <unsigned int> (waveHdr.dataChunkLength));
float secondLength = static_cast <float> (waveHdr.dataChunkLength / waveHdr.bytesPerSecond); float secondLength = static_cast <float> (waveHdr.dataChunkLength) / static_cast <float> (waveHdr.bytesPerSecond);
float milliSecondLength = atof (ch); float milliSecondLength = atof (ch);
return (secondLength == 0.0 ? milliSecondLength : secondLength); return (secondLength == 0.0 ? milliSecondLength : secondLength);

View file

@ -875,7 +875,6 @@ void Waypoint::SaveExperienceTab (void)
void Waypoint::InitExperienceTab (void) void Waypoint::InitExperienceTab (void)
{ {
ExtensionHeader header;
int i, j; int i, j;
delete [] g_experienceData; delete [] g_experienceData;
@ -907,7 +906,16 @@ void Waypoint::InitExperienceTab (void)
// if file exists, read the experience data from it // if file exists, read the experience data from it
if (fp.IsValid ()) if (fp.IsValid ())
{ {
fp.Read (&header, sizeof (ExtensionHeader)); ExtensionHeader header;
memset (&header, 0, sizeof (header));
if (fp.Read (&header, sizeof (ExtensionHeader)) == 0)
{
AddLogEntry (true, LL_ERROR, "Experience data damaged (unable to read header)");
fp.Close ();
return;
}
fp.Close (); fp.Close ();
if (strncmp (header.header, FH_EXPERIENCE, strlen (FH_EXPERIENCE)) == 0) if (strncmp (header.header, FH_EXPERIENCE, strlen (FH_EXPERIENCE)) == 0)
@ -956,10 +964,8 @@ void Waypoint::SaveVisibilityTab (void)
if (g_numWaypoints == 0) if (g_numWaypoints == 0)
return; return;
if (m_visLUT == NULL)
AddLogEntry (true, LL_FATAL, "Can't save visibility tab. Bad data.");
ExtensionHeader header; ExtensionHeader header;
memset (&header, 0, sizeof (ExtensionHeader));
// parse header // parse header
memset (header.header, 0, sizeof (header.header)); memset (header.header, 0, sizeof (header.header));
@ -1000,7 +1006,13 @@ void Waypoint::InitVisibilityTab (void)
} }
// read the header of the file // read the header of the file
fp.Read (&header, sizeof (ExtensionHeader)); if (fp.Read (&header, sizeof (ExtensionHeader)) == 0)
{
AddLogEntry (true, LL_ERROR, "Vistable damaged (unable to read header)");
fp.Close ();
return;
}
if (strncmp (header.header, FH_VISTABLE, strlen (FH_VISTABLE)) != 0 || header.fileVersion != FV_VISTABLE || header.pointNumber != g_numWaypoints) if (strncmp (header.header, FH_VISTABLE, strlen (FH_VISTABLE)) != 0 || header.fileVersion != FV_VISTABLE || header.pointNumber != g_numWaypoints)
{ {
@ -1056,9 +1068,11 @@ void Waypoint::InitTypes (void)
bool Waypoint::Load (void) bool Waypoint::Load (void)
{ {
WaypointHeader header;
File fp (CheckSubfolderFile (), "rb"); File fp (CheckSubfolderFile (), "rb");
WaypointHeader header;
memset (&header, 0, sizeof (WaypointHeader));
if (fp.IsValid ()) if (fp.IsValid ())
{ {
fp.Read (&header, sizeof (header)); fp.Read (&header, sizeof (header));
@ -1067,7 +1081,7 @@ bool Waypoint::Load (void)
{ {
if (header.fileVersion != FV_WAYPOINT) if (header.fileVersion != FV_WAYPOINT)
{ {
sprintf (m_infoBuffer, "%s.pwf - incorrect waypoint file version (expected '%i' found '%i')", GetMapName (), FV_WAYPOINT, static_cast <int> (header.fileVersion)); sprintf (m_infoBuffer, "%s.pwf - incorrect waypoint file version (expected '%d' found '%d')", GetMapName (), FV_WAYPOINT, static_cast <int> (header.fileVersion));
AddLogEntry (true, LL_ERROR, m_infoBuffer); AddLogEntry (true, LL_ERROR, m_infoBuffer);
fp.Close (); fp.Close ();
@ -1083,6 +1097,15 @@ bool Waypoint::Load (void)
} }
else else
{ {
if (header.pointNumber == 0 || header.pointNumber >= MAX_WAYPOINTS)
{
sprintf (m_infoBuffer, "%s.pwf - waypoint file contains illegal number of waypoints (mapname: '%s', header: '%s')", GetMapName (), GetMapName (), header.mapName);
AddLogEntry (true, LL_ERROR, m_infoBuffer);
fp.Close ();
return false;
}
Init (); Init ();
g_numWaypoints = header.pointNumber; g_numWaypoints = header.pointNumber;
@ -1198,8 +1221,8 @@ void Waypoint::Save (void)
memset (header.header, 0, sizeof (header.header)); memset (header.header, 0, sizeof (header.header));
strcpy (header.header, FH_WAYPOINT); strcpy (header.header, FH_WAYPOINT);
strcpy (header.author, STRING (g_hostEntity->v.netname)); strncpy (header.author, STRING (g_hostEntity->v.netname), sizeof (header.author));
strncpy (header.mapName, GetMapName (), 31); strncpy (header.mapName, GetMapName (), sizeof (header.mapName));
header.mapName[31] = 0; header.mapName[31] = 0;
header.fileVersion = FV_WAYPOINT; header.fileVersion = FV_WAYPOINT;
@ -2134,11 +2157,18 @@ bool Waypoint::LoadPathMatrix (void)
} }
// read path & distance matrixes // read path & distance matrixes
fp.Read (m_pathMatrix, sizeof (int), g_numWaypoints * g_numWaypoints); if (fp.Read (m_pathMatrix, sizeof (int), g_numWaypoints * g_numWaypoints) == 0)
fp.Read (m_distMatrix, sizeof (int), g_numWaypoints * g_numWaypoints); {
fp.Close ();
return false;
}
// and close the file if (fp.Read (m_distMatrix, sizeof (int), g_numWaypoints * g_numWaypoints) == 0)
fp.Close (); {
fp.Close ();
return false;
}
fp.Close (); // and close the file
return true; return true;
} }
@ -2467,6 +2497,7 @@ Waypoint::Waypoint (void)
m_lastJumpWaypoint = -1; m_lastJumpWaypoint = -1;
m_cacheWaypointIndex = -1; m_cacheWaypointIndex = -1;
m_findWPIndex = -1; m_findWPIndex = -1;
m_facingAtIndex = -1;
m_visibilityIndex = 0; m_visibilityIndex = 0;
m_isOnLadder = false; m_isOnLadder = false;
@ -2483,6 +2514,9 @@ Waypoint::Waypoint (void)
m_distMatrix = NULL; m_distMatrix = NULL;
m_pathMatrix = NULL; m_pathMatrix = NULL;
for (int i = 0; i < MAX_WAYPOINTS; i++)
m_paths[i] = NULL;
} }
Waypoint::~Waypoint (void) Waypoint::~Waypoint (void)
@ -2614,8 +2648,11 @@ WaypointDownloadError WaypointDownloader::DoDownload (void)
{ {
recvSize = recv (socketHandle, buffer, ChunkSize, 0); recvSize = recv (socketHandle, buffer, ChunkSize, 0);
fp.Write (buffer, recvSize); if (recvSize > 0)
fp.Flush (); {
fp.Write (buffer, recvSize);
fp.Flush ();
}
} while (recvSize != 0); } while (recvSize != 0);