Fixes for various bugs noticed by Coverity static analysis tool.
parent
8c5d8d35ab
commit
cea585162d
|
@ -161,6 +161,7 @@ IMAGEFILE *iV_LoadImageFile(const char *fileName)
|
|||
if (retval != 3)
|
||||
{
|
||||
debug(LOG_ERROR, "Bad line in \"%s\".", fileName);
|
||||
delete imageFile;
|
||||
return NULL;
|
||||
}
|
||||
std::string spriteName = imageDir + tmpName;
|
||||
|
@ -171,6 +172,7 @@ IMAGEFILE *iV_LoadImageFile(const char *fileName)
|
|||
if (!iV_loadImage_PNG(spriteName.c_str(), imageRect->data))
|
||||
{
|
||||
debug(LOG_ERROR, "Failed to find image \"%s\" listed in \"%s\".", spriteName.c_str(), fileName);
|
||||
delete imageFile;
|
||||
return NULL;
|
||||
}
|
||||
imageRect->siz = Vector2i(imageRect->data->width, imageRect->data->height);
|
||||
|
|
|
@ -1409,7 +1409,7 @@ static bool NETprocessSystemMessage(NETQUEUE playerQueue, uint8_t type)
|
|||
debug(LOG_ERROR, "Incomplete NET_SEND_TO_PLAYER.");
|
||||
break;
|
||||
}
|
||||
if (sender > MAX_PLAYERS || (receiver > MAX_PLAYERS && receiver != NET_ALL_PLAYERS))
|
||||
if (sender >= MAX_PLAYERS || (receiver >= MAX_PLAYERS && receiver != NET_ALL_PLAYERS))
|
||||
{
|
||||
debug(LOG_ERROR, "Bad NET_SEND_TO_PLAYER.");
|
||||
break;
|
||||
|
@ -1489,7 +1489,7 @@ static bool NETprocessSystemMessage(NETQUEUE playerQueue, uint8_t type)
|
|||
NETuint32_t(&num);
|
||||
bool isSentByCorrectClient = responsibleFor(playerQueue.index, player);
|
||||
isSentByCorrectClient = isSentByCorrectClient || (playerQueue.index == NET_HOST_ONLY && playerQueue.index != selectedPlayer); // Let host spoof other people's NET_SHARE_GAME_QUEUE messages, but not our own. This allows the host to spoof a GAME_PLAYER_LEFT message (but spoofing any message when the player is still there will fail with desynch).
|
||||
if (!isSentByCorrectClient || player > MAX_PLAYERS)
|
||||
if (!isSentByCorrectClient || player >= MAX_PLAYERS)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -1530,7 +1530,7 @@ static bool NETprocessSystemMessage(NETQUEUE playerQueue, uint8_t type)
|
|||
|
||||
NETbeginDecode(playerQueue, NET_PLAYER_INFO);
|
||||
NETuint32_t(&indexLen);
|
||||
if (indexLen > MAX_PLAYERS || (playerQueue.index != NET_HOST_ONLY && indexLen > 1))
|
||||
if (indexLen >= MAX_PLAYERS || (playerQueue.index != NET_HOST_ONLY && indexLen > 1))
|
||||
{
|
||||
debug(LOG_ERROR, "MSG_PLAYER_INFO: Bad number of players updated");
|
||||
NETend();
|
||||
|
@ -2671,7 +2671,8 @@ bool NEThostGame(const char* SessionName, const char* PlayerName,
|
|||
gamestruct.future3 = 0xBAD03; // for future use
|
||||
gamestruct.future4 = 0xBAD04; // for future use
|
||||
|
||||
selectedPlayer= NET_CreatePlayer(PlayerName);
|
||||
selectedPlayer = NET_CreatePlayer(PlayerName);
|
||||
ASSERT_OR_RETURN(false, selectedPlayer < MAX_PLAYERS, "Failed to create player");
|
||||
realSelectedPlayer = selectedPlayer;
|
||||
NetPlay.isHost = true;
|
||||
NetPlay.isHostAlive = true;
|
||||
|
@ -2822,7 +2823,8 @@ bool NETfindGame(void)
|
|||
|
||||
if (NetPlay.games[gamecount].desc.host[0] == '\0')
|
||||
{
|
||||
strncpy(NetPlay.games[gamecount].desc.host, getSocketTextAddress(tcp_socket), sizeof(NetPlay.games[gamecount].desc.host));
|
||||
memset(NetPlay.games[gamecount].desc.host, 0, sizeof(NetPlay.games[gamecount].desc.host));
|
||||
strncpy(NetPlay.games[gamecount].desc.host, getSocketTextAddress(tcp_socket), sizeof(NetPlay.games[gamecount].desc.host) - 1);
|
||||
}
|
||||
|
||||
++gamecount;
|
||||
|
|
|
@ -717,6 +717,7 @@ static bool dataImageLoad(const char *fileName, void **ppData)
|
|||
if (!iV_loadImage_PNG(fileName, psSprite))
|
||||
{
|
||||
debug( LOG_ERROR, "IMGPAGE load failed" );
|
||||
free(psSprite);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1358,6 +1358,8 @@ static void intProcessEditStats(UDWORD id)
|
|||
debugMenuDroidDeliveryPoint.factoryType = REPAIR_FLAG;
|
||||
debugMenuDroidDeliveryPoint.factoryInc = 0;
|
||||
debugMenuDroidDeliveryPoint.player = selectedPlayer;
|
||||
debugMenuDroidDeliveryPoint.selected = false;
|
||||
debugMenuDroidDeliveryPoint.psNext = NULL;
|
||||
startDeliveryPosition(&debugMenuDroidDeliveryPoint);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -1964,7 +1964,7 @@ bool recvTeamRequest(NETQUEUE queue)
|
|||
NETuint8_t(&team);
|
||||
NETend();
|
||||
|
||||
if (player > MAX_PLAYERS || team > MAX_PLAYERS)
|
||||
if (player >= MAX_PLAYERS || team >= MAX_PLAYERS)
|
||||
{
|
||||
debug(LOG_NET, "NET_TEAMREQUEST invalid, player %d team, %d", (int) player, (int) team);
|
||||
debug(LOG_ERROR, "Invalid NET_TEAMREQUEST from player %d: Tried to change player %d (team %d)",
|
||||
|
@ -2020,7 +2020,7 @@ bool recvReadyRequest(NETQUEUE queue)
|
|||
NETbool(&bReady);
|
||||
NETend();
|
||||
|
||||
if (player > MAX_PLAYERS)
|
||||
if (player >= MAX_PLAYERS)
|
||||
{
|
||||
debug(LOG_ERROR, "Invalid NET_READY_REQUEST from player %d: player id = %d",
|
||||
queue.index, (int)player);
|
||||
|
@ -2179,7 +2179,7 @@ bool recvColourRequest(NETQUEUE queue)
|
|||
NETuint8_t(&col);
|
||||
NETend();
|
||||
|
||||
if (player > MAX_PLAYERS)
|
||||
if (player >= MAX_PLAYERS)
|
||||
{
|
||||
debug(LOG_ERROR, "Invalid NET_COLOURREQUEST from player %d: Tried to change player %d to colour %d",
|
||||
queue.index, (int)player, (int)col);
|
||||
|
@ -2213,7 +2213,7 @@ bool recvPositionRequest(NETQUEUE queue)
|
|||
NETend();
|
||||
debug(LOG_NET, "Host received position request from player %d to %d", player, position);
|
||||
|
||||
if (player > MAX_PLAYERS || position > MAX_PLAYERS)
|
||||
if (player >= MAX_PLAYERS || position >= MAX_PLAYERS)
|
||||
{
|
||||
debug(LOG_ERROR, "Invalid NET_POSITIONREQUEST from player %d: Tried to change player %d to %d",
|
||||
queue.index, (int)player, (int)position);
|
||||
|
|
|
@ -1732,7 +1732,7 @@ UDWORD msgStackPush(SDWORD CBtype, SDWORD plFrom, SDWORD plTo, const char *tStr,
|
|||
{
|
||||
debug(LOG_WZ, "msgStackPush: pushing message type %d to pos %d", CBtype, msgStackPos + 1);
|
||||
|
||||
if (msgStackPos >= MAX_MSG_STACK)
|
||||
if (msgStackPos + 1 >= MAX_MSG_STACK)
|
||||
{
|
||||
debug(LOG_ERROR, "msgStackPush() - stack full");
|
||||
return false;
|
||||
|
|
|
@ -269,7 +269,7 @@ void updateMultiStatsLoses(void)
|
|||
// update kills
|
||||
void updateMultiStatsKills(BASE_OBJECT *psKilled,UDWORD player)
|
||||
{
|
||||
if (Cheated || player > MAX_PLAYERS)
|
||||
if (Cheated || player >= MAX_PLAYERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -6243,9 +6243,9 @@ bool scrResetPlayerVisibility(void)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (player < 0 || player > MAX_PLAYERS)
|
||||
if (player < 0 || player >= MAX_PLAYERS)
|
||||
{
|
||||
ASSERT( false, "scrResetPlayerVisibility: invalid player" );
|
||||
ASSERT(false, "Invalid player %d", player);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue