Skip to content

Commit

Permalink
Fixed: More compiler warnings
Browse files Browse the repository at this point in the history
Set-but-unused variables, checking fread() return values.

NOTE: A couple of potential bugs here need checking.
  • Loading branch information
skyjake committed Mar 22, 2013
1 parent 9169805 commit eab7868
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 32 deletions.
9 changes: 6 additions & 3 deletions doomsday/client/src/client/cl_main.cpp
Expand Up @@ -80,10 +80,13 @@ void Cl_InitID(void)
srand(time(NULL));
if((file = fopen("client.id", "rb")) != NULL)
{
DENG_UNUSED(fread(&clientID, sizeof(clientID), 1, file)); // return value ignored
clientID = ULONG(clientID);
if(fread(&clientID, sizeof(clientID), 1, file))
{
clientID = ULONG(clientID);
fclose(file);
return;
}
fclose(file);
return;
}
// Ah-ha, we need to generate a new ID.
clientID = (ident_t)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/map/gamemap.cpp
Expand Up @@ -747,7 +747,7 @@ void GameMap_LinkLineDef(GameMap* map, LineDef* lineDef)
}

// Would LineDef intersect this?
if(LineDef_PointOnSide(lineDef, from) < 0 != LineDef_PointOnSide(lineDef, to) < 0)
if((LineDef_PointOnSide(lineDef, from) < 0) != (LineDef_PointOnSide(lineDef, to) < 0))
{
Blockmap_CreateCellAndLinkObjectXY(blockmap, x, y, lineDef);
}
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/src/map/r_world.cpp
Expand Up @@ -1566,6 +1566,8 @@ boolean R_UpdateSector(Sector *sec, boolean forceUpdate)
changed = true;
}

DENG_UNUSED(changed); /// @todo Should it be used? -jk

This comment has been minimized.

Copy link
@danij-deng

danij-deng Mar 23, 2013

Collaborator

How is it that compiler thinks this is unused? Clearly it is.


return planeChanged;
}

Expand Down
11 changes: 5 additions & 6 deletions doomsday/client/src/render/rend_bias.cpp
Expand Up @@ -922,8 +922,8 @@ void SB_RendPoly(struct ColorRawf_s* rcolors, biassurface_t* bsuf,
float sectorLightLevel,
de::MapElement const *mapElement, uint elmIdx)
{
uint i;
boolean forced;
uint i;
//boolean forced;

// Apply sectorlight bias. Note: Distance darkening is not used
// with bias lights.
Expand All @@ -943,7 +943,7 @@ void SB_RendPoly(struct ColorRawf_s* rcolors, biassurface_t* bsuf,
memset(&trackApplied, 0, sizeof(trackApplied));

// Has any of the old affected lights changed?
forced = false;
//forced = false;

if(doUpdateAffected)
{
Expand Down Expand Up @@ -1258,13 +1258,12 @@ void SB_EvalPoint(float light[4], vertexillum_t* illum,

if(illum)
{
boolean willOverride = false;
boolean willOverride = false;

// Combine the casted light from each source.
for(aff = affecting; aff->source; aff++)
{
float *casted =
SB_GetCasted(illum, aff->index, affectedSources);
float *casted = SB_GetCasted(illum, aff->index, affectedSources);

if(aff->overrider &&
(casted[CR] > 0 || casted[CG] > 0 || casted[CB] > 0))
Expand Down
8 changes: 5 additions & 3 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -2993,15 +2993,15 @@ void Rend_RenderSurfaceVectors()
HEdge* hedge = GameMap_HEdge(theMap, i);
float x, y, bottom, top;
Sector* backSec;
LineDef* line;
//LineDef* line;
Surface* suf;
vec3f_t origin;

if(!hedge->lineDef || !hedge->sector ||
(hedge->lineDef->inFlags & LF_POLYOBJ))
continue;

line = hedge->lineDef;
//line = hedge->lineDef;
x = hedge->HE_v1origin[VX] + (hedge->HE_v2origin[VX] - hedge->HE_v1origin[VX]) / 2;
y = hedge->HE_v1origin[VY] + (hedge->HE_v2origin[VY] - hedge->HE_v1origin[VY]) / 2;

Expand Down Expand Up @@ -3646,7 +3646,7 @@ void R_DrawLightRange()
#define BLOCK_HEIGHT (BLOCK_WIDTH * 255.0f)
#define BORDER (20)

ui_color_t color;
//ui_color_t color;
float c, off;
int i;

Expand All @@ -3660,9 +3660,11 @@ void R_DrawLightRange()

glTranslatef(BORDER, BORDER, 0);

/*
color.red = 0.2f;
color.green = 0;
color.blue = 0.6f;
*/

// Draw an outside border.
glColor4f(1, 1, 0, 1);
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/src/resource/material.cpp
Expand Up @@ -242,6 +242,8 @@ Material::Decoration::Stage *Material::Decoration::Stage::fromDef(ded_decorlight
}
}

/// @todo Should use sysFlareIdx below instead of def.sysFlareIdx? -jk

This comment has been minimized.

Copy link
@danij-deng

danij-deng Mar 23, 2013

Collaborator

Well spotted, yes sysFlareIdx should be used here as the above logic is used to "normalize" these values. Will fix...


return new Stage(def.tics, def.variance, Vector2f(def.pos), def.elevation,
Vector3f(def.color), def.radius, def.haloRadius,
Stage::LightLevels(def.lightLevels),
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/src/resource/tga.cpp
Expand Up @@ -413,6 +413,8 @@ uint8_t* TGA_Load(FileHandle* file, int* w, int* h, int* pixelSize)
pixbytes = 4;
}

DENG_UNUSED(format);

*pixelSize = pixbytes;

// Read the pixel data.
Expand Down
3 changes: 3 additions & 0 deletions doomsday/client/src/ui/ui_main.cpp
Expand Up @@ -1789,6 +1789,9 @@ void UI_InitColumns(ui_object_t* ob)
if(width[i])
last = width[i];
}

DENG_UNUSED(last); /// @todo Remove? -jk

// Calculate the offset for each column.
maxw = ob->geometry.size.width - 4 * UI_BORDER - (dat->count > dat->numvis ? UI_BAR_WDH : 0);
sep = maxw - w;
Expand Down
1 change: 1 addition & 0 deletions doomsday/server/src/server/sv_main.cpp
Expand Up @@ -467,6 +467,7 @@ void Sv_ExecuteCommand(void)
// New format includes flags and command source.
// Flags are currently unused but added for future expansion.
flags = Reader_ReadUInt16(msgReader);
DENG_UNUSED(flags);
cmdSource = Reader_ReadByte(msgReader);
break;

Expand Down
9 changes: 4 additions & 5 deletions doomsday/server/src/server/sv_pool.cpp
Expand Up @@ -121,13 +121,13 @@ static dt_mobj_t dummyZeroMobj;
*/
void Sv_InitPools(void)
{
uint i;
uint startTime;
de::Time startedAt;
uint i;

// Clients don't register anything.
if(isClient) return;

startTime = Timer_RealMilliseconds();
LOG_AS("Sv_InitPools");

// Set base priority scores for all the delta types.
for(i = 0; i < NUM_DELTA_TYPES; ++i)
Expand Down Expand Up @@ -170,8 +170,7 @@ void Sv_InitPools(void)
Sv_RegisterWorld(&initialRegister, true);

// How much time did we spend?
DEBUG_Message(("Sv_InitPools: World registered, done in %.2f seconds.\n",
(Timer_RealMilliseconds() - startTime) / 1000.0f));
LOG_DEBUG("World registered in %.2f seconds.") << startedAt.since();
}

/**
Expand Down
37 changes: 29 additions & 8 deletions doomsday/tools/md2tool/md2tool.c
Expand Up @@ -264,6 +264,10 @@ void DoError(int code)
case MTERR_LISTFILE_NA:
printf("The specified list file doesn't exist.\n");
break;

case MTERR_READ_FAILED:
printf("Failed reading from file.\n");
exit(4);
}
}

Expand All @@ -275,7 +279,10 @@ void *Load(FILE *file, int offset, int len)
{
void *ptr = malloc(len);
fseek(file, offset, SEEK_SET);
fread(ptr, len, 1, file);
if(!fread(ptr, len, 1, file))
{
DoError(MTERR_READ_FAILED);
}
return ptr;
}

Expand Down Expand Up @@ -336,13 +343,19 @@ int ModelOpen(model_t *mo, const char *filename)

memset(mo, 0, sizeof(*mo));
strcpy(mo->fileName, fn);
fread(&mo->header, sizeof(mo->header), 1, file);
if(!fread(&mo->header, sizeof(mo->header), 1, file))
{
DoError(MTERR_READ_FAILED);
}
hd = &mo->header;
inf = &mo->info;
if(hd->magic == DMD_MAGIC)
{
// Read the chunks.
fread(&chunk, sizeof(chunk), 1, file);
if(!fread(&chunk, sizeof(chunk), 1, file))
{
DoError(MTERR_READ_FAILED);
}
while(chunk.type != DMC_END)
{
switch(chunk.type)
Expand All @@ -358,7 +371,10 @@ int ModelOpen(model_t *mo, const char *filename)
chunk.type, chunk.length);
}
// Read the next chunk.
fread(&chunk, sizeof(chunk), 1, file);
if(!fread(&chunk, sizeof(chunk), 1, file))
{
DoError(MTERR_READ_FAILED);
}
}

// Allocate and load in the data.
Expand All @@ -383,7 +399,10 @@ int ModelOpen(model_t *mo, const char *filename)
else if(hd->magic == MD2_MAGIC)
{
rewind(file);
fread(&oldhd, sizeof(oldhd), 1, file);
if(!fread(&oldhd, sizeof(oldhd), 1, file))
{
DoError(MTERR_READ_FAILED);
}

// Convert it to DMD data but keep it as an MD2.
hd->magic = MD2_MAGIC;
Expand Down Expand Up @@ -1919,9 +1938,11 @@ void ReadText(FILE *file, char *buf, int size)
int i;

memset(buf, 0, size);
fgets(buf, size - 1, file);
i = strlen(buf) - 1;
if(buf[i] == '\n') buf[i] = 0;
if(fgets(buf, size - 1, file))
{
i = strlen(buf) - 1;
if(buf[i] == '\n') buf[i] = 0;
}
}

//===========================================================================
Expand Down
3 changes: 2 additions & 1 deletion doomsday/tools/md2tool/md2tool.h
Expand Up @@ -21,7 +21,8 @@ enum
MTERR_INVALID_SKIN_NUMBER,
MTERR_INVALID_FRAME_NUMBER,
MTERR_NO_FILES,
MTERR_LISTFILE_NA
MTERR_LISTFILE_NA,
MTERR_READ_FAILED
};

#define MD2_MAGIC 0x32504449
Expand Down
24 changes: 20 additions & 4 deletions doomsday/tools/texc/import.cpp
Expand Up @@ -101,10 +101,18 @@ void Import(char *wadFile, char *outFile)
}
printf("Importing textures from %s.\n", wadFile);

fread(&info, sizeof(info), 1, file);
if(!fread(&info, sizeof(info), 1, file))
{
perror(wadFile);
return;
}
lumps = new lumpinfo_t[info.numlumps];
fseek(file, info.infotableofs, SEEK_SET);
fread(lumps, sizeof(*lumps), info.numlumps, file);
if(fread(lumps, sizeof(*lumps), info.numlumps, file) < size_t(info.numlumps))
{
perror(wadFile);
return;
}

// Open the output file.
if((out = fopen(outFile, "wt")) == NULL)
Expand All @@ -119,7 +127,11 @@ void Import(char *wadFile, char *outFile)
if(i < 0) goto not_found;
fseek(file, lumps[i].filepos, SEEK_SET);
dir = (patchdir_t*) malloc(lumps[i].size);
fread(dir, lumps[i].size, 1, file);
if(!fread(dir, lumps[i].size, 1, file))
{
perror(wadFile);
return;
}

// Process the texture lumps.
for(group = 1; group <= 2; group++)
Expand All @@ -134,7 +146,11 @@ void Import(char *wadFile, char *outFile)

fseek(file, lumps[i].filepos, SEEK_SET);
data = new char[lumps[i].size];
fread(data, lumps[i].size, 1, file);
if(!fread(data, lumps[i].size, 1, file))
{
perror(wadFile);
return;
}
count = *(int*) data;
texCount += count;
dict = (int*) data + 1;
Expand Down
6 changes: 5 additions & 1 deletion doomsday/tools/texc/texc.cpp
Expand Up @@ -525,7 +525,11 @@ void Compile(char *fileName)
length = ftell(file);
rewind(file);
sourcePos = source = new unsigned char[length + 1];
fread(source, length, 1, file);
if(!fread(source, length, 1, file))
{
perror(fileName);
return;
}
source[length] = 0;
fclose(file);

Expand Down

0 comments on commit eab7868

Please sign in to comment.