Skip to content

Commit

Permalink
fix several -Wunused-result warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Aug 18, 2023
1 parent 87ebe3a commit 92594e2
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 21 deletions.
3 changes: 2 additions & 1 deletion Quake/cl_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ static int CL_GetDemoMessage (void)
}

// get the next message
fread (&net_message.cursize, 4, 1, cls.demofile);
if (! fread(&net_message.cursize, 4, 1, cls.demofile))
Sys_Error ("Demo read error");
VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
for (i = 0 ; i < 3 ; i++)
{
Expand Down
8 changes: 7 additions & 1 deletion Quake/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,13 @@ void Con_DebugLog(const char *msg)
if (log_fd == -1)
return;

write(log_fd, msg, strlen(msg));
if (write(log_fd, msg, strlen(msg)) < 0)
{
close (log_fd);
log_fd = -1;
con_debuglog = false;
fprintf (stderr, "Error writing to log file\n");
}
}


Expand Down
4 changes: 2 additions & 2 deletions Quake/gl_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -2157,7 +2157,7 @@ static byte *Mod_LoadVisibilityExternal(FILE* f)
byte* visdata;

filelen = 0;
fread(&filelen, 1, 4, f);
if (!fread(&filelen, 4, 1, f)) return NULL;
filelen = LittleLong(filelen);
if (filelen <= 0) return NULL;
Con_DPrintf("...%d bytes visibility data\n", filelen);
Expand All @@ -2173,7 +2173,7 @@ static void Mod_LoadLeafsExternal(FILE* f)
void* in;

filelen = 0;
fread(&filelen, 1, 4, f);
if (!fread(&filelen, 4, 1, f)) return;
filelen = LittleLong(filelen);
if (filelen <= 0) return;
Con_DPrintf("...%d bytes leaf data\n", filelen);
Expand Down
13 changes: 7 additions & 6 deletions Quake/gl_texmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ static void TexMgr_Imagedump_f (void)
for (glt = active_gltextures; glt; glt = glt->next)
{
q_strlcpy (tempname, glt->name, sizeof(tempname));
while ( (c = strchr(tempname, ':')) ) *c = '_';
while ( (c = strchr(tempname, '/')) ) *c = '_';
while ( (c = strchr(tempname, '*')) ) *c = '_';
while ((c = strchr(tempname, ':')) != NULL) *c = '_';
while ((c = strchr(tempname, '/')) != NULL) *c = '_';
while ((c = strchr(tempname, '*')) != NULL) *c = '_';
q_snprintf(tganame, sizeof(tganame), "imagedump/%s.tga", tempname);

GL_Bind (glt);
Expand Down Expand Up @@ -470,7 +470,8 @@ void TexMgr_LoadPalette (void)

mark = Hunk_LowMark ();
pal = (byte *) Hunk_Alloc (768);
fread (pal, 1, 768, f);
if (!fread(pal, 768, 1, f))
Sys_Error ("Failed reading gfx/palette.lmp");
fclose(f);

//standard palette, 255 is transparent
Expand Down Expand Up @@ -692,8 +693,7 @@ int TexMgr_PadConditional (int s)
{
if (s < TexMgr_SafeTextureSize(s))
return TexMgr_Pad(s);
else
return s;
return s;
}

/*
Expand Down Expand Up @@ -1281,6 +1281,7 @@ void TexMgr_ReloadImage (gltexture_t *glt, int shirt, int pants)
byte translation[256];
byte *src, *dst, *data = NULL, *translated;
int mark, size, i;

//
// get source data
//
Expand Down
6 changes: 4 additions & 2 deletions Quake/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ byte *Image_LoadPCX (FILE *f, int *width, int *height)

start = ftell (f); //save start of file (since we might be inside a pak file, SEEK_SET might not be the start of the pcx)

fread(&pcx, sizeof(pcx), 1, f);
if (!fread(&pcx, sizeof(pcx), 1, f))
Sys_Error ("Failed reading header from '%s'", loadfilename);
pcx.xmin = (unsigned short)LittleShort (pcx.xmin);
pcx.ymin = (unsigned short)LittleShort (pcx.ymin);
pcx.xmax = (unsigned short)LittleShort (pcx.xmax);
Expand All @@ -472,7 +473,8 @@ byte *Image_LoadPCX (FILE *f, int *width, int *height)

//load palette
fseek (f, start + com_filesize - 768, SEEK_SET);
fread (palette, 1, 768, f);
if (!fread (palette, 768, 1, f))
Sys_Error ("Failed reading palette from '%s'", loadfilename);

//back to start of image data
fseek (f, start + sizeof(pcx), SEEK_SET);
Expand Down
10 changes: 7 additions & 3 deletions Quake/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,14 @@ void M_ScanSaves (void)
loadable[i] = false;
q_snprintf (name, sizeof(name), "%s/s%i.sav", com_gamedir, i);
f = fopen (name, "r");
if (!f)
if (!f) {
continue;
fscanf (f, "%i\n", &version);
fscanf (f, "%79s\n", name);
}
if (fscanf(f, "%i\n", &version) != 1 ||
fscanf(f, "%79s\n", name) != 1) {
fclose(f);
continue;
}
q_strlcpy (m_filenames[i], name, SAVEGAME_COMMENT_LENGTH+1);

// change _ back to space
Expand Down
14 changes: 8 additions & 6 deletions Quake/snd_wave.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ FGetLittleLong
static int FGetLittleLong (FILE *f)
{
int v;
fread(&v, 1, sizeof(v), f);
if (!fread(&v, sizeof(v), 1, f))
return -1;
return LittleLong(v);
}

Expand All @@ -49,7 +50,8 @@ FGetLittleShort
static short FGetLittleShort(FILE *f)
{
short v;
fread(&v, 1, sizeof(v), f);
if (!fread(&v, sizeof(v), 1, f))
return -1;
return LittleShort(v);
}

Expand All @@ -60,12 +62,11 @@ WAV_ReadChunkInfo
*/
static int WAV_ReadChunkInfo(FILE *f, char *name)
{
int len, r;
int len;

name[4] = 0;

r = fread(name, 1, 4, f);
if (r != 4)
if (!fread(name, 4, 1, f))
return -1;

len = FGetLittleLong(f);
Expand Down Expand Up @@ -224,7 +225,8 @@ int S_WAV_CodecReadStream(snd_stream_t *stream, int bytes, void *buffer)
if (bytes > remaining)
bytes = remaining;
stream->fh.pos += bytes;
fread(buffer, 1, bytes, stream->fh.file);
if (!fread(buffer, bytes, 1, stream->fh.file))
return -1;
if (stream->info.width == 2)
{
samples = bytes / 2;
Expand Down

0 comments on commit 92594e2

Please sign in to comment.