From bed1ecc63a1609df8d1b86ffbe7dd8d6eab1f764 Mon Sep 17 00:00:00 2001 From: rawr51919 Date: Sat, 12 Aug 2023 20:16:55 -0300 Subject: [PATCH 1/3] Fixed all warnings remaining in BSPC code --- aas_facemerging.c | 2 +- aas_gsubdiv.c | 2 +- bspc.c | 9 +++++++-- deps/botlib/be_aas_reach.c | 6 +++--- deps/botlib/l_precomp.c | 10 +++++----- deps/botlib/l_precomp.h | 4 ++-- deps/botlib/l_script.c | 2 ++ deps/qcommon/cm_patch.c | 2 +- deps/qcommon/cm_trace.c | 4 ++-- deps/qcommon/unzip.c | 34 +++++++++++++++++++++++----------- l_bsp_hl.c | 2 +- l_bsp_q2.c | 6 ++++-- l_bsp_q3.c | 5 +++-- l_bsp_sin.c | 6 ++++-- l_cmd.c | 2 +- l_log.c | 2 +- l_mem.c | 3 ++- leakfile.c | 6 +++--- map_hl.c | 2 +- map_q1.c | 2 +- portals.c | 8 ++++---- textures.c | 2 +- 22 files changed, 73 insertions(+), 48 deletions(-) diff --git a/aas_facemerging.c b/aas_facemerging.c index b6ac76d..fc17dfc 100644 --- a/aas_facemerging.c +++ b/aas_facemerging.c @@ -217,7 +217,7 @@ int AAS_CanMergePlaneFaces(tmp_area_t *tmparea, int planenum) { tmp_area_t *frontarea, *backarea; tmp_face_t *face1; - int side1, merge, faceflags; + int side1 = 0, merge = 0, faceflags = 0; frontarea = backarea = NULL; merge = false; diff --git a/aas_gsubdiv.c b/aas_gsubdiv.c index d3cf222..c982af3 100644 --- a/aas_gsubdiv.c +++ b/aas_gsubdiv.c @@ -528,7 +528,7 @@ tmp_node_t *AAS_LadderSubdivideArea_r(tmp_node_t *tmpnode) tmp_area_t *tmparea, *frontarea, *backarea; tmp_face_t *face1; tmp_node_t *tmpnode1, *tmpnode2; - vec3_t lowestpoint, normal = {0, 0, 1}; + vec3_t lowestpoint = {0}, normal = {0, 0, 1}; plane_t *plane; winding_t *w; diff --git a/bspc.c b/bspc.c index b1a0a12..c95da67 100644 --- a/bspc.c +++ b/bspc.c @@ -200,12 +200,17 @@ void CreateAASFilesForAllBSPFiles(char *quakepath) // for (qf = bspfiles; qf; qf = qf->next) { - sprintf(aasfile, "%s/%s", qf->pakfile, qf->origname); + if (snprintf(aasfile, sizeof(aasfile), "%s/%s", qf->pakfile, qf->origname) >= sizeof(aasfile)) + { + fprintf(stderr, "Error: AAS file name too long."); + } Log_Print("found %s\n", aasfile); strcpy(&aasfile[strlen(aasfile)-strlen(".bsp")], ".aas"); for (qf2 = aasfiles; qf2; qf2 = qf2->next) { - sprintf(buf, "%s/%s", qf2->pakfile, qf2->origname); + if (snprintf(buf, sizeof(buf), "%s/%s", qf2->pakfile, qf2->origname) >= sizeof(buf)) { + fprintf(stderr, "Error: AAS file name too long."); + } if (!stricmp(aasfile, buf)) { Log_Print("found %s\n", buf); diff --git a/deps/botlib/be_aas_reach.c b/deps/botlib/be_aas_reach.c index 5dfa020..fdabaeb 100644 --- a/deps/botlib/be_aas_reach.c +++ b/deps/botlib/be_aas_reach.c @@ -1065,8 +1065,8 @@ int AAS_Reachability_Step_Barrier_WaterJump_WalkOffLedge(int area1num, int area2 float length, ground_bestlength, water_bestlength, ground_bestdist, water_bestdist; vec3_t v1, v2, v3, v4, tmpv, p1area1, p1area2, p2area1, p2area2; vec3_t normal, ort, edgevec, start, end, dir; - vec3_t ground_beststart, ground_bestend, ground_bestnormal; - vec3_t water_beststart, water_bestend, water_bestnormal; + vec3_t ground_beststart = {0}, ground_bestend = {0}, ground_bestnormal = {0}; + vec3_t water_beststart = {0}, water_bestend = {0}, water_bestnormal = {0}; vec3_t invgravity = {0, 0, 1}; vec3_t testpoint; aas_plane_t *plane; @@ -2380,7 +2380,7 @@ int AAS_Reachability_Ladder(int area1num, int area2num) float face1area, face2area, bestface1area, bestface2area; float phys_jumpvel, maxjumpheight; vec3_t area1point, area2point, v1, v2, up = {0, 0, 1}; - vec3_t mid, lowestpoint, start, end, sharededgevec, dir; + vec3_t mid, lowestpoint = {0}, start, end, sharededgevec, dir; aas_area_t *area1, *area2; aas_face_t *face1, *face2, *ladderface1, *ladderface2; aas_plane_t *plane1, *plane2; diff --git a/deps/botlib/l_precomp.c b/deps/botlib/l_precomp.c index 04c17db..353a2e2 100644 --- a/deps/botlib/l_precomp.c +++ b/deps/botlib/l_precomp.c @@ -739,7 +739,7 @@ int PC_ExpandBuiltinDefine(source_t *source, token_t *deftoken, define_t *define case BUILTIN_DATE: { t = time(NULL); - curtime = ctime(&t); + curtime = ctime((const long int *)&t); strcpy(token->string, "\""); strncat(token->string, curtime+4, 7); strncat(token->string+7, curtime+20, 4); @@ -754,7 +754,7 @@ int PC_ExpandBuiltinDefine(source_t *source, token_t *deftoken, define_t *define case BUILTIN_TIME: { t = time(NULL); - curtime = ctime(&t); + curtime = ctime((const long int *)&t); strcpy(token->string, "\""); strncat(token->string, curtime+11, 8); strcat(token->string, "\""); @@ -1702,7 +1702,7 @@ int PC_EvaluateTokens(source_t *source, token_t *tokens, signed long int *intval int lastoperatortype = 0; // operator_t operator_heap[MAX_OPERATORS]; - int numoperators = 0; + int numoperators = lastoperatortype = 0; value_t value_heap[MAX_VALUES]; int numvalues = 0; @@ -2997,7 +2997,7 @@ source_t *LoadSourceFile(const char *filename) source = (source_t *) GetMemory(sizeof(source_t)); Com_Memset(source, 0, sizeof(source_t)); - strncpy(source->filename, filename, MAX_PATH); + strncpy(source->filename, filename, MAX_PATH-1); source->scriptstack = script; source->tokens = NULL; source->defines = NULL; @@ -3030,7 +3030,7 @@ source_t *LoadSourceMemory(char *ptr, int length, char *name) source = (source_t *) GetMemory(sizeof(source_t)); Com_Memset(source, 0, sizeof(source_t)); - strncpy(source->filename, name, MAX_PATH); + strncpy(source->filename, name, MAX_PATH-1); source->scriptstack = script; source->tokens = NULL; source->defines = NULL; diff --git a/deps/botlib/l_precomp.h b/deps/botlib/l_precomp.h index 7d9e45b..5fd7320 100644 --- a/deps/botlib/l_precomp.h +++ b/deps/botlib/l_precomp.h @@ -90,8 +90,8 @@ typedef struct indent_s //source file typedef struct source_s { - char filename[1024]; //file name of the script - char includepath[1024]; //path to include files + char filename[8192]; //file name of the script + char includepath[9215]; //path to include files punctuation_t *punctuations; //punctuations to use script_t *scriptstack; //stack with scripts of the source token_t *tokens; //tokens to read first diff --git a/deps/botlib/l_script.c b/deps/botlib/l_script.c index d4da773..d5661d5 100644 --- a/deps/botlib/l_script.c +++ b/deps/botlib/l_script.c @@ -47,6 +47,8 @@ typedef enum {qfalse, qtrue} qboolean; #endif //SCREWUP +int COM_Compress( char *data_p ); + #ifdef BOTLIB //include files for usage in the bot library #include "qcommon/q_shared.h" diff --git a/deps/qcommon/cm_patch.c b/deps/qcommon/cm_patch.c index 75ad7f8..b664ddd 100644 --- a/deps/qcommon/cm_patch.c +++ b/deps/qcommon/cm_patch.c @@ -1379,7 +1379,7 @@ void CM_TraceThroughPatchCollide( traceWork_t *tw, const struct patchCollide_s * float offset, enterFrac, leaveFrac, t; patchPlane_t *planes; facet_t *facet; - float plane[4], bestplane[4]; + float plane[4] = {0}, bestplane[4] = {0}; vec3_t startp, endp; #ifndef BSPC static cvar_t *cv; diff --git a/deps/qcommon/cm_trace.c b/deps/qcommon/cm_trace.c index 9e8abec..1f5829b 100644 --- a/deps/qcommon/cm_trace.c +++ b/deps/qcommon/cm_trace.c @@ -137,9 +137,9 @@ float SquareRootFloat(float number) { x = number * 0.5F; y = number; - i = * ( long * ) &y; + i = (long)y; i = 0x5f3759df - ( i >> 1 ); - y = * ( float * ) &i; + y = (float)i; y = y * ( f - ( x * y * y ) ); y = y * ( f - ( x * y * y ) ); return number * y; diff --git a/deps/qcommon/unzip.c b/deps/qcommon/unzip.c index e298a84..7e8b9eb 100644 --- a/deps/qcommon/unzip.c +++ b/deps/qcommon/unzip.c @@ -1108,7 +1108,10 @@ static int unzlocal_getShort (FILE* fin, uLong *pX) { short v; - fread( &v, sizeof(v), 1, fin ); + if (fread(&v, sizeof(v), 1, fin) != sizeof(v)) + { + perror("Could not read data from compressed file."); + } *pX = LittleShort( v); return UNZ_OK; @@ -1137,7 +1140,10 @@ static int unzlocal_getLong (FILE *fin, uLong *pX) { int v; - fread( &v, sizeof(v), 1, fin ); + if (fread(&v, sizeof(v), 1, fin) != sizeof(v)) + { + perror("Could not read data from compressed file."); + } *pX = LittleLong( v); return UNZ_OK; @@ -1412,8 +1418,10 @@ extern int unzClose (unzFile file) return UNZ_PARAMERROR; s=(unz_s*)file; - if (s->pfile_in_zip_read!=NULL) - unzCloseCurrentFile(file); + if (s->pfile_in_zip_read != NULL) + { + unzCloseCurrentFile(file); + } fclose(s->file); TRYFREE(s); @@ -1737,8 +1745,10 @@ extern int unzLocateFile (unzFile file, const char *szFileName, int iCaseSensiti if (file==NULL) return UNZ_PARAMERROR; - if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) - return UNZ_PARAMERROR; + if (strlen(szFileName) >= UNZ_MAXFILENAMEINZIP) + { + return UNZ_PARAMERROR; + } s=(unz_s*)file; if (!s->current_file_ok) @@ -1816,8 +1826,10 @@ static int unzlocal_CheckCurrentFileCoherencyHeader (unz_s* s, uInt* piSizeVar, (s->cur_file_info.compression_method!=Z_DEFLATED)) err=UNZ_BADZIPFILE; - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* date/time */ - err=UNZ_ERRNO; + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* date/time */ + { + err = UNZ_ERRNO; + } if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* crc */ err=UNZ_ERRNO; @@ -1876,8 +1888,8 @@ extern int unzOpenCurrentFile (unzFile file) if (!s->current_file_ok) return UNZ_PARAMERROR; - if (s->pfile_in_zip_read != NULL) - unzCloseCurrentFile(file); + if (s->pfile_in_zip_read != NULL) + unzCloseCurrentFile(file); if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) @@ -3036,7 +3048,6 @@ static int huft_build(uInt *b, uInt n, uInt s, const uInt *d, const uInt *e, inf int y; /* number of dummy codes added */ uInt z; /* number of entries in current table */ - /* Generate counts for each bit length */ p = c; #define C0 *p++ = 0; @@ -3196,6 +3207,7 @@ static int huft_build(uInt *b, uInt n, uInt s, const uInt *d, const uInt *e, inf /* Return Z_BUF_ERROR if we were given an incomplete table */ return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK; + puts(inflate_copyright); } diff --git a/l_bsp_hl.c b/l_bsp_hl.c index 7677ab6..0cb1cc3 100644 --- a/l_bsp_hl.c +++ b/l_bsp_hl.c @@ -640,7 +640,7 @@ void HL_WriteBSPFile (char *filename) //============================================================================ -#define ENTRIES(a) (sizeof(a)/sizeof(*(a))) +#define ENTRIES(a) ((&a)[1] - a) #define ENTRYSIZE(a) (sizeof(*(a))) unsigned ArrayUsage( char *szItem, int items, int maxitems, int itemsize ) diff --git a/l_bsp_q2.c b/l_bsp_q2.c index 445ff30..a86aac0 100644 --- a/l_bsp_q2.c +++ b/l_bsp_q2.c @@ -922,7 +922,8 @@ void Q2_LoadBSPFileTexinfo (char *filename) q2_header = GetMemory(sizeof(dheader_t)); f = fopen (filename, "rb"); - fread (q2_header, sizeof(dheader_t), 1, f); + if (fread(q2_header, sizeof(dheader_t), 1, f) != sizeof(dheader_t)) + Error("Failed to read data from IBSP file", filename); // swap the header for (i=0 ; i< sizeof(dheader_t)/4 ; i++) @@ -938,7 +939,8 @@ void Q2_LoadBSPFileTexinfo (char *filename) ofs = q2_header->lumps[LUMP_TEXINFO].fileofs; fseek (f, ofs, SEEK_SET); - fread (texinfo, length, 1, f); + if (fread(texinfo, length, 1, f) != length) + Error("Failed to read texture info from IBSP file", filename); fclose (f); numtexinfo = length / sizeof(texinfo_t); diff --git a/l_bsp_q3.c b/l_bsp_q3.c index 6239617..38f074d 100644 --- a/l_bsp_q3.c +++ b/l_bsp_q3.c @@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "l_qfiles.h" #include "l_bsp_q3.h" #include "l_bsp_ent.h" +#include void Q3_ParseEntities (void); void Q3_PrintBSPFileSizes(void); @@ -523,8 +524,8 @@ void Q3_SwapBSPFile( void ) { Q3_SwapBlock( (int *)q3_dbrushsides, q3_numbrushsides * sizeof( q3_dbrushsides[0] ) ); // vis - ((int *)&q3_visBytes)[0] = LittleLong( ((int *)&q3_visBytes)[0] ); - ((int *)&q3_visBytes)[1] = LittleLong( ((int *)&q3_visBytes)[1] ); + ((int32_t *)q3_visBytes)[0] = LittleLong(((int32_t *)q3_visBytes)[0]); + ((int32_t *)q3_visBytes)[1] = LittleLong(((int32_t *)q3_visBytes)[1]); // drawverts (don't swap colors ) for ( i = 0 ; i < q3_numDrawVerts ; i++ ) { diff --git a/l_bsp_sin.c b/l_bsp_sin.c index 154551f..19218fa 100644 --- a/l_bsp_sin.c +++ b/l_bsp_sin.c @@ -916,7 +916,8 @@ void Sin_LoadBSPFileTexinfo (char *filename) sin_header = GetMemory(sizeof(sin_dheader_t)); f = fopen (filename, "rb"); - fread (sin_header, sizeof(sin_dheader_t), 1, f); + if (fread(sin_header, sizeof(sin_dheader_t), 1, f) != sizeof(sin_dheader_t)) + Error("Failed to read data from IBSP file", filename); // swap the header for (i=0 ; i< sizeof(sin_dheader_t)/4 ; i++) @@ -932,7 +933,8 @@ void Sin_LoadBSPFileTexinfo (char *filename) ofs = sin_header->lumps[SIN_LUMP_TEXINFO].fileofs; fseek (f, ofs, SEEK_SET); - fread (sin_texinfo, length, 1, f); + if (fread(sin_texinfo, length, 1, f) != length) + Error("Failed to read texture info from IBSP file", filename); fclose (f); sin_numtexinfo = length / sizeof(sin_texinfo_t); diff --git a/l_cmd.c b/l_cmd.c index 3a8ab63..3699198 100644 --- a/l_cmd.c +++ b/l_cmd.c @@ -332,7 +332,7 @@ char *ExpandPath (char *path) char *ExpandPathAndArchive (char *path) { char *expanded; - char archivename[1024]; + char archivename[1025]; expanded = ExpandPath (path); diff --git a/l_log.c b/l_log.c index 6a69c2b..af82986 100644 --- a/l_log.c +++ b/l_log.c @@ -61,7 +61,7 @@ void Log_Open(char *filename) printf("can't open the log file %s\n", filename); return; } //end if - strncpy(logfile.filename, filename, MAX_LOGFILENAMESIZE); + strncpy(logfile.filename, filename, MAX_LOGFILENAMESIZE-1); printf("Opened log %s\n", logfile.filename); } //end of the function Log_Create //=========================================================================== diff --git a/l_mem.c b/l_mem.c index 2636b68..46c14da 100644 --- a/l_mem.c +++ b/l_mem.c @@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "qbsp.h" #include "l_log.h" +#include int allocedmemory; @@ -410,7 +411,7 @@ void *Hunk_Alloc(int size) { memhunk_t *h; - if (!size) return (void *) memhunk_high_size; + if (!size) return (void *) (intptr_t)memhunk_high_size; // h = GetClearedMemory(size + sizeof(memhunk_t)); h->ptr = (char *) h + sizeof(memhunk_t); diff --git a/leakfile.c b/leakfile.c index 924b34d..f83db94 100644 --- a/leakfile.c +++ b/leakfile.c @@ -45,7 +45,7 @@ void LeakFile (tree_t *tree) { vec3_t mid; FILE *linefile; - char filename[1024]; + char filename[2048]; node_t *node; int count; @@ -68,8 +68,8 @@ void LeakFile (tree_t *tree) while (node->occupied > 1) { int next; - portal_t *p, *nextportal; - node_t *nextnode; + portal_t *p, *nextportal = NULL; + node_t *nextnode = NULL; int s; // find the best portal exit diff --git a/map_hl.c b/map_hl.c index 88e4fa7..e212919 100644 --- a/map_hl.c +++ b/map_hl.c @@ -633,7 +633,7 @@ bspbrush_t *HL_SplitBrushWithFace(bspbrush_t *brush, hl_dface_t *face) hl_dplane_t plane; vec_t *v1, *v2; vec3_t normal, edgevec; - bspbrush_t *front, *back, *brushlist; + bspbrush_t *front = NULL, *back, *brushlist; memcpy(&plane, &hl_dplanes[face->planenum], sizeof(hl_dplane_t)); //check on which side of the plane the face is diff --git a/map_q1.c b/map_q1.c index ede944d..11b5a4f 100644 --- a/map_q1.c +++ b/map_q1.c @@ -689,7 +689,7 @@ bspbrush_t *Q1_SplitBrushWithFace(bspbrush_t *brush, q1_dface_t *face) q1_dplane_t plane; vec_t *v1, *v2; vec3_t normal, edgevec; - bspbrush_t *front, *back, *brushlist; + bspbrush_t *front = NULL, *back, *brushlist; memcpy(&plane, &q1_dplanes[face->planenum], sizeof(q1_dplane_t)); //check on which side of the plane the face is diff --git a/portals.c b/portals.c index cde4f60..67d907c 100644 --- a/portals.c +++ b/portals.c @@ -408,13 +408,13 @@ void MakeNodePortal (node_t *node) portal_t *new_portal, *p; winding_t *w; vec3_t normal; - float dist; - int side; + float dist = 0.0f; + int side = 0; w = BaseWindingForNode (node); // clip the portal by all the other portals in the node - for (p = node->portals; p && w; p = p->next[side]) + for (p = node->portals; p && w; p = p->next[side]) { if (p->nodes[0] == node) { @@ -482,7 +482,7 @@ void SplitNodePortals (node_t *node) { portal_t *p, *next_portal, *new_portal; node_t *f, *b, *other_node; - int side; + int side = 0; plane_t *plane; winding_t *frontwinding, *backwinding; diff --git a/textures.c b/textures.c index 76cc0fd..f17a447 100644 --- a/textures.c +++ b/textures.c @@ -35,7 +35,7 @@ textureref_t textureref[MAX_MAP_TEXTURES]; int FindMiptex (char *name) { int i; - char path[1024]; + char path[10240]; miptex_t *mt; for (i = 0; i < nummiptex; i++) From 173092b0cef30a234599d0d1d50324905aa687a1 Mon Sep 17 00:00:00 2001 From: rawr51919 Date: Sat, 12 Aug 2023 20:22:24 -0300 Subject: [PATCH 2/3] Refined a couple things, archivename buffer didn't need expansiong --- deps/qcommon/unzip.c | 1 + l_cmd.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/deps/qcommon/unzip.c b/deps/qcommon/unzip.c index 7e8b9eb..32b3840 100644 --- a/deps/qcommon/unzip.c +++ b/deps/qcommon/unzip.c @@ -3048,6 +3048,7 @@ static int huft_build(uInt *b, uInt n, uInt s, const uInt *d, const uInt *e, inf int y; /* number of dummy codes added */ uInt z; /* number of entries in current table */ + /* Generate counts for each bit length */ p = c; #define C0 *p++ = 0; diff --git a/l_cmd.c b/l_cmd.c index 3699198..04c709b 100644 --- a/l_cmd.c +++ b/l_cmd.c @@ -332,13 +332,13 @@ char *ExpandPath (char *path) char *ExpandPathAndArchive (char *path) { char *expanded; - char archivename[1025]; + char archivename[1024]; expanded = ExpandPath (path); if (archive) { - sprintf (archivename, "%s/%s", archivedir, path); + sprintf (archivename, "%s/%s", archivedir, path-1); QCopyFile (expanded, archivename); } return expanded; From f436e6b6158e48b7210c240434895351e5451b0f Mon Sep 17 00:00:00 2001 From: rawr51919 Date: Sat, 12 Aug 2023 20:24:06 -0300 Subject: [PATCH 3/3] Just make archivename buffer 2048 --- l_cmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/l_cmd.c b/l_cmd.c index 04c709b..11aee9e 100644 --- a/l_cmd.c +++ b/l_cmd.c @@ -332,13 +332,13 @@ char *ExpandPath (char *path) char *ExpandPathAndArchive (char *path) { char *expanded; - char archivename[1024]; + char archivename[2048]; expanded = ExpandPath (path); if (archive) { - sprintf (archivename, "%s/%s", archivedir, path-1); + sprintf (archivename, "%s/%s", archivedir, path); QCopyFile (expanded, archivename); } return expanded;