Skip to content

Commit

Permalink
Fix various issues prompted by running valgrind and cppcheck. Patch r…
Browse files Browse the repository at this point in the history
…eviewed by Cyp.
  • Loading branch information
perim committed Jan 18, 2011
1 parent e65751e commit 2d6ea37
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 45 deletions.
18 changes: 5 additions & 13 deletions src/design.cpp
Expand Up @@ -1295,9 +1295,6 @@ intChooseSystemStats( DROID_TEMPLATE *psTemplate )
return psStats;
}

/* set SHOWTEMPLATENAME to 0 to show template components in edit box */
#define SHOWTEMPLATENAME 0

const char *GetDefaultTemplateName(DROID_TEMPLATE *psTemplate)
{
// NOTE: At this time, savegames can support a max of 60. We are using WIDG_MAXSTR (currently 80 )for display
Expand All @@ -1310,7 +1307,8 @@ const char *GetDefaultTemplateName(DROID_TEMPLATE *psTemplate)
*/
if(psTemplate->droidType == DROID_TRANSPORTER)
{
return _("Transport");
sstrcpy(aCurrName, _("Transport"));
return aCurrName;
}

/*
Expand All @@ -1336,7 +1334,7 @@ const char *GetDefaultTemplateName(DROID_TEMPLATE *psTemplate)
}

compIndex = psTemplate->asParts[COMP_BODY];
ASSERT_OR_RETURN( NULL, compIndex < numBodyStats, "Invalid range referenced for numBodyStats, %d > %d", compIndex, numBodyStats);
ASSERT_OR_RETURN("", compIndex < numBodyStats, "Invalid range referenced for numBodyStats, %d > %d", compIndex, numBodyStats);
psStats = (COMPONENT_STATS *) (asBodyStats + compIndex);
if ( psTemplate->asParts[COMP_BODY] != 0 )
{
Expand All @@ -1353,7 +1351,7 @@ const char *GetDefaultTemplateName(DROID_TEMPLATE *psTemplate)
}

compIndex = psTemplate->asParts[COMP_PROPULSION];
ASSERT_OR_RETURN( NULL, compIndex < numPropulsionStats, "Invalid range referenced for numPropulsionStats, %d > %d", compIndex, numPropulsionStats);
ASSERT_OR_RETURN("", compIndex < numPropulsionStats, "Invalid range referenced for numPropulsionStats, %d > %d", compIndex, numPropulsionStats);
psStats = (COMPONENT_STATS *) (asPropulsionStats + compIndex);
if ( psTemplate->asParts[COMP_PROPULSION] != 0 )
{
Expand All @@ -1371,13 +1369,8 @@ const char *GetDefaultTemplateName(DROID_TEMPLATE *psTemplate)
return aCurrName;
}


static void intSetEditBoxTextFromTemplate( DROID_TEMPLATE *psTemplate )
{
#if SHOWTEMPLATENAME
widgSetString(psWScreen, IDDES_NAMEBOX, getStatName(psTemplate));
#else

sstrcpy(aCurrName, "");

/* show component names if default template else show stat name */
Expand All @@ -1387,11 +1380,10 @@ static void intSetEditBoxTextFromTemplate( DROID_TEMPLATE *psTemplate )
}
else
{
sstrcpy(aCurrName, GetDefaultTemplateName(psTemplate));
GetDefaultTemplateName(psTemplate); // sets aCurrName
}

widgSetString(psWScreen, IDDES_NAMEBOX, aCurrName);
#endif
}

/* Set all the design bar graphs from a design template */
Expand Down
2 changes: 0 additions & 2 deletions src/display.cpp
Expand Up @@ -1431,8 +1431,6 @@ UDWORD dispX,dispY,dispR;
return(psReturn);
}

UWORD lastangle; // debugging only

// Dummy structure stats used for positioning delivery points.
static STRUCTURE_STATS ReposStats;
static BOOL ReposValid = false;
Expand Down
31 changes: 2 additions & 29 deletions src/game.cpp
Expand Up @@ -11662,33 +11662,7 @@ static void plotFeature(char *backDropSprite)
//increment to the start of the data
pFileData += FEATURE_HEADER_SIZE;

// Check the file version
if (psHeader->version <= VERSION_19)
{
if (psHeader->version < VERSION_14)
{
// most (all?) maps use revision 8
sizeOfSaveFeature = sizeof(SAVE_FEATURE_V2);
psSaveFeature = (SAVE_FEATURE_V2*) pFileData;
}
else
{
// supposedly, All versions up to 19 are compatible with SAVE_STRUCTURE_V2
// so this isn't needed. Adding check just in case.
//sizeOfSaveFeature = sizeof(SAVE_FEATURE_V14);
//psSaveFeatureV14 = (SAVE_FEATURE_V14*) pFileData;
debug(LOG_ERROR, "Please make a new ticket and upload %s to wz2100.net. This map (>14) is not supported at this time.", psLevel->apDataFiles[0]);
return;
}
}
else
{
// AFAIK, at this time, nothing uses this size.
//sizeOfSaveFeature = sizeof(SAVE_FEATURE);
//psSaveFeature = (SAVE_FEATURE*) pFileData;
debug(LOG_ERROR, "Please make a new ticket and upload %s to wz2100.net. This map (>19) is not supported at this time.", psLevel->apDataFiles[0]);
return;
}
sizeOfSaveFeature = sizeof(SAVE_FEATURE_V2);

if ((sizeOfSaveFeature * psHeader->quantity + FEATURE_HEADER_SIZE) > fileSize)
{
Expand All @@ -11700,7 +11674,7 @@ static void plotFeature(char *backDropSprite)
for (count = 0; count < psHeader->quantity; count++, pFileData += sizeOfSaveFeature)
{
// All versions up to 19 are compatible with V2.
memcpy(psSaveFeature, pFileData, sizeof(SAVE_STRUCTURE_V2));
psSaveFeature = (SAVE_FEATURE_V2*) pFileData;

// we only care about oil
if (strncmp(psSaveFeature->name, "OilResource", 11) == 0)
Expand All @@ -11722,4 +11696,3 @@ static void plotFeature(char *backDropSprite)
backDropSprite[3 * ((yy * BACKDROP_HACK_WIDTH) + xx) + 2] = color.byte.b;
}
}

3 changes: 2 additions & 1 deletion src/projectile.cpp
Expand Up @@ -385,13 +385,14 @@ bool proj_SendProjectile(WEAPON *psWeap, SIMPLE_OBJECT *psAttacker, int player,

bool proj_SendProjectileAngled(WEAPON *psWeap, SIMPLE_OBJECT *psAttacker, int player, Vector3i target, BASE_OBJECT *psTarget, bool bVisible, int weapon_slot, int min_angle)
{
PROJECTILE * psProj = new PROJECTILE(ProjectileTrackerID |(gameTime2 >>4), player);
WEAPON_STATS *psStats = &asWeaponStats[psWeap->nStat];

ASSERT_OR_RETURN( false, psWeap->nStat < numWeaponStats, "Invalid range referenced for numWeaponStats, %d > %d", psWeap->nStat, numWeaponStats);
ASSERT_OR_RETURN( false, psStats != NULL, "Invalid weapon stats" );
ASSERT_OR_RETURN( false, psTarget == NULL || !psTarget->died, "Aiming at dead target!" );

PROJECTILE *psProj = new PROJECTILE(ProjectileTrackerID | (realTime >> 4), player);

/* get muzzle offset */
if (psAttacker == NULL)
{
Expand Down

0 comments on commit 2d6ea37

Please sign in to comment.