Fix various minor issues pointed out by Coverity scanner.

master
per 2013-11-07 00:17:07 +01:00
parent b366d80ca5
commit dda1585f95
9 changed files with 12 additions and 36 deletions

View File

@ -524,25 +524,12 @@ void screenDoDumpToDiskIfRequired(void)
iV_Image image = { 0, 0, 8, NULL };
if (!screendump_required) return;
debug( LOG_3D, "Saving screenshot %s\n", fileName );
debug(LOG_3D, "Saving screenshot %s", fileName);
if (image.width != screenWidth || image.height != screenHeight)
{
if (image.bmp != NULL)
{
free(image.bmp);
}
image.width = screenWidth;
image.height = screenHeight;
image.bmp = (unsigned char *)malloc(channelsPerPixel * image.width * image.height);
image.width = screenWidth;
image.height = screenHeight;
image.bmp = (unsigned char *)malloc(channelsPerPixel * image.width * image.height);
if (image.bmp == NULL)
{
image.width = 0; image.height = 0;
debug(LOG_ERROR, "Couldn't allocate memory");
return;
}
}
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, image.width, image.height, GL_RGB, GL_UNSIGNED_BYTE, image.bmp);

View File

@ -49,7 +49,11 @@ struct Socket
*
* All non-listening sockets will only use the first socket handle.
*/
Socket() : ready(false), writeError(false), deleteLater(false), isCompressed(false), readDisconnected(false), zDeflateInSize(0) {}
Socket() : ready(false), writeError(false), deleteLater(false), isCompressed(false), readDisconnected(false), zDeflateInSize(0)
{
memset(&zDeflate, 0, sizeof(zDeflate));
memset(&zInflate, 0, sizeof(zInflate));
}
~Socket();
SOCKET fd[SOCK_COUNT];

View File

@ -78,7 +78,6 @@ static SDWORD bucketCalculateZ(RENDER_TYPE objectType, void* pObject)
position.x = position.x - player.p.x;
position.z = -(position.z - player.p.z);
position.y = position.y;
/* 16 below is HACK!!! */
z = pie_RotateProject(&position,&pixel) - 16;

View File

@ -100,7 +100,7 @@ void updateChallenge(bool gameWon)
fStr = strrchr(sRequestResult, '/');
fStr++; // skip slash
if (fStr == '\0')
if (*fStr == '\0')
{
debug(LOG_ERROR, "Bad path to challenge file (%s)", sRequestResult);
return;

View File

@ -3440,13 +3440,6 @@ bool gameLoadV(PHYSFS_file* fileHandle, unsigned int version)
}
debug(LOG_SAVE, "Savegame is of type: %u", saveGameData.sGame.type);
// Campaign games are fine, only skirmish games are broken in v36
if (saveGameData.sGame.type != CAMPAIGN && version == VERSION_36)
{
debug(LOG_ERROR, "Skirmish savegames of version %u are not supported in this release.", version);
return false;
}
game.type = saveGameData.sGame.type;
/* Test mod list */
if (version >= VERSION_38)

View File

@ -65,10 +65,6 @@ static inline MESSAGE* createMessage(MESSAGE_TYPE msgType, UDWORD player)
ASSERT_OR_RETURN(NULL, player < MAX_PLAYERS, "Bad player");
ASSERT_OR_RETURN(NULL, msgType < MSG_TYPES, "Bad message");
if (player >= MAX_PLAYERS || msgType >= MSG_TYPES)
{
return NULL;
}
// Allocate memory for the message, and on failure return a NULL pointer
newMsg = (MESSAGE *)malloc(sizeof(MESSAGE));

View File

@ -1255,7 +1255,7 @@ static Vector2i moveGetObstacleVector(DROID *psDroid, Vector2i dest)
numObst += 1;
}
if (dir == Vector2i(0, 0))
if (dir == Vector2i(0, 0) || numObst == 0)
{
return dest;
}

View File

@ -591,10 +591,6 @@ bool scrOrderDroidStatsLoc(void)
ASSERT_OR_RETURN(false, psDroid != NULL, "Invalid Unit pointer");
ASSERT_OR_RETURN(false, psStats != NULL, "Invalid object pointer");
if (psDroid == NULL)
{
return false;
}
if ((x < 0) || (x > (SDWORD)mapWidth * TILE_UNITS) ||
(y < 0) || (y > (SDWORD)mapHeight * TILE_UNITS))

View File

@ -872,6 +872,7 @@ bool lineOfFire(const SIMPLE_OBJECT* psViewer, const BASE_OBJECT* psTarget, int
ASSERT_OR_RETURN(false, psViewer != NULL, "Invalid shooter pointer!");
ASSERT_OR_RETURN(false, psTarget != NULL, "Invalid target pointer!");
ASSERT_OR_RETURN(false, psViewer->type == OBJ_DROID || psViewer->type == OBJ_STRUCTURE, "Bad viewer type");
if (psViewer->type == OBJ_DROID)
{