From 92594e23bf93b136cf825ab253d1d4acf2c20c3e Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Fri, 18 Aug 2023 20:33:10 +0300 Subject: [PATCH] fix several -Wunused-result warnings. --- Quake/cl_demo.c | 3 ++- Quake/console.c | 8 +++++++- Quake/gl_model.c | 4 ++-- Quake/gl_texmgr.c | 13 +++++++------ Quake/image.c | 6 ++++-- Quake/menu.c | 10 +++++++--- Quake/snd_wave.c | 14 ++++++++------ 7 files changed, 37 insertions(+), 21 deletions(-) diff --git a/Quake/cl_demo.c b/Quake/cl_demo.c index 6eca03669..6bc667f4c 100644 --- a/Quake/cl_demo.c +++ b/Quake/cl_demo.c @@ -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++) { diff --git a/Quake/console.c b/Quake/console.c index 2023f1664..89e1a3fb2 100644 --- a/Quake/console.c +++ b/Quake/console.c @@ -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"); + } } diff --git a/Quake/gl_model.c b/Quake/gl_model.c index 6fc3c1812..46a83a993 100644 --- a/Quake/gl_model.c +++ b/Quake/gl_model.c @@ -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); @@ -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); diff --git a/Quake/gl_texmgr.c b/Quake/gl_texmgr.c index ba2a8e669..fead0d5ca 100644 --- a/Quake/gl_texmgr.c +++ b/Quake/gl_texmgr.c @@ -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); @@ -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 @@ -692,8 +693,7 @@ int TexMgr_PadConditional (int s) { if (s < TexMgr_SafeTextureSize(s)) return TexMgr_Pad(s); - else - return s; + return s; } /* @@ -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 // diff --git a/Quake/image.c b/Quake/image.c index fcbf1b59b..0adbbf829 100644 --- a/Quake/image.c +++ b/Quake/image.c @@ -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); @@ -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); diff --git a/Quake/menu.c b/Quake/menu.c index 18b4b3e6a..c25e7a8c7 100644 --- a/Quake/menu.c +++ b/Quake/menu.c @@ -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 diff --git a/Quake/snd_wave.c b/Quake/snd_wave.c index 584c4de4c..35e3ccf98 100644 --- a/Quake/snd_wave.c +++ b/Quake/snd_wave.c @@ -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); } @@ -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); } @@ -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); @@ -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;