From: TimePath Date: Sun, 6 May 2018 10:51:40 +0000 (+1000) Subject: gcc: appease the hardening warnings X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b0d0b345f70f630411f952d1d65b1e8e75330076;p=xonotic%2Fnetradiant.git gcc: appease the hardening warnings --- diff --git a/CMakeLists.txt b/CMakeLists.txt index aa1028d6..95fa439f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,6 +109,9 @@ add_definitions(-DRADIANT_PATCH_VERSION="${NetRadiant_VERSION_PATCH}") add_definitions(-DRADIANT_ABOUTMSG="${NetRadiant_ABOUT}") +add_definitions(-D_GLIBCXX_DEBUG=1) +add_definitions(-D_GLIBCXX_DEBUG_PEDANTIC=1) + if (NOT CMAKE_BUILD_TYPE MATCHES Release) add_definitions(-D_DEBUG=1) endif () diff --git a/contrib/bobtoolz/DTrainDrawer.cpp b/contrib/bobtoolz/DTrainDrawer.cpp index 0a3307de..0165fa08 100644 --- a/contrib/bobtoolz/DTrainDrawer.cpp +++ b/contrib/bobtoolz/DTrainDrawer.cpp @@ -220,7 +220,7 @@ public: AddSplineControl(control, pSP); for (int j = 2;; j++) { - char buffer[16]; + char buffer[18]; sprintf(buffer, "control%i", j); e.SpawnString(buffer, NULL, &control); diff --git a/contrib/bobtoolz/DTreePlanter.h b/contrib/bobtoolz/DTreePlanter.h index 5d661232..3b38c5e6 100644 --- a/contrib/bobtoolz/DTreePlanter.h +++ b/contrib/bobtoolz/DTreePlanter.h @@ -20,6 +20,7 @@ #ifndef __DTREE_H__ #define __DTREE_H__ +#include #include "qerplugin.h" #include "signal/isignal.h" #include "string/string.h" @@ -83,7 +84,7 @@ public: buf[len] = '\0'; // parser will do the cleanup, dont delete. - fread(buf, len, 1, file); + assert(fread(buf, len, 1, file)); CScriptParser parser; parser.SetScript(buf); diff --git a/contrib/bobtoolz/bsploader.cpp b/contrib/bobtoolz/bsploader.cpp index 020cf4d8..a4e74031 100644 --- a/contrib/bobtoolz/bsploader.cpp +++ b/contrib/bobtoolz/bsploader.cpp @@ -1,4 +1,5 @@ #include +#include #include "bsploader.h" #include "dialogs/dialogs-gtk.h" #include "cmdlib.h" @@ -66,7 +67,7 @@ bool LoadFile(const char *filename, byte **bufferptr) length = FileLength(f); buffer = new byte[length + 1]; buffer[length] = 0; - fread(buffer, 1, length, f); + assert(fread(buffer, 1, length, f)); fclose(f); *bufferptr = buffer; diff --git a/contrib/bobtoolz/cportals.cpp b/contrib/bobtoolz/cportals.cpp index ab944ed8..3fd39202 100644 --- a/contrib/bobtoolz/cportals.cpp +++ b/contrib/bobtoolz/cportals.cpp @@ -21,6 +21,7 @@ #include #include +#include #include "misc.h" @@ -244,10 +245,10 @@ void CPortals::Load() in = fopen(fn, "rt"); - fgets(buf, LINE_BUF, in); - fgets(buf, LINE_BUF, in); - fgets(buf, LINE_BUF, in); - fgets(buf, LINE_BUF, in); + assert(fgets(buf, LINE_BUF, in)); + assert(fgets(buf, LINE_BUF, in)); + assert(fgets(buf, LINE_BUF, in)); + assert(fgets(buf, LINE_BUF, in)); unsigned int n; for (n = 0; n < p_count; n++) { diff --git a/contrib/bobtoolz/lists.cpp b/contrib/bobtoolz/lists.cpp index 9830c376..d9e5cbed 100644 --- a/contrib/bobtoolz/lists.cpp +++ b/contrib/bobtoolz/lists.cpp @@ -34,9 +34,7 @@ bool LoadExclusionList(char *filename, std::list *exclusionList) int cnt = 0; while (!feof(eFile)) { memset(buffer, 0, 256); - fscanf(eFile, "%s\n", buffer); - - if (strlen(buffer) > 0) { + if (fscanf(eFile, "%s\n", buffer)) { exclusionList->push_back(buffer); } else { cnt++; @@ -60,9 +58,7 @@ bool LoadGList(char *filename, ui::ListStore loadlist) int cnt = 0; while (!feof(eFile)) { memset(buffer, 0, 256); - fscanf(eFile, "%s\n", buffer); - - if (strlen(buffer) > 0) { + if (fscanf(eFile, "%s\n", buffer)) { char *buffer2 = new char[strlen(buffer) + 1]; strcpy(buffer2, buffer); loadlist.append(0, buffer2); diff --git a/contrib/bobtoolz/misc.cpp b/contrib/bobtoolz/misc.cpp index 95274655..9e6c2b8b 100644 --- a/contrib/bobtoolz/misc.cpp +++ b/contrib/bobtoolz/misc.cpp @@ -198,9 +198,9 @@ bool Q_Exec(const char *pCmd, bool bCreateConsole) // NOTE: we could use that to detect when a step finishes. But then it // would not work for remote compiling stuff. // execlp (pCmd, pCmd, NULL); - system(pCmd); + int ret = system(pCmd); printf("system() returned"); - _exit(0); + _exit(ret); break; } return true; diff --git a/contrib/prtview/portals.cpp b/contrib/prtview/portals.cpp index c4d3b04d..eb14f1d4 100644 --- a/contrib/prtview/portals.cpp +++ b/contrib/prtview/portals.cpp @@ -69,7 +69,7 @@ bool CBspPortal::Build(char *def) char *c = def; unsigned int n; int dummy1, dummy2; - int res_cnt, i; + int res_cnt = 0, i; if (portals.hint_flags) { res_cnt = sscanf(def, "%u %d %d %d", &point_count, &dummy1, &dummy2, (int *) &hint); diff --git a/libs/bytestreamutils.h b/libs/bytestreamutils.h index 69ec3755..45749ce0 100644 --- a/libs/bytestreamutils.h +++ b/libs/bytestreamutils.h @@ -151,7 +151,7 @@ inline float istream_read_float32_be( InputStreamType& istream ){ template inline typename InputStreamType::byte_type istream_read_byte( InputStreamType& istream ){ - typename InputStreamType::byte_type b; + typename InputStreamType::byte_type b = 0; istream.read( &b, sizeof( typename InputStreamType::byte_type ) ); return b; } diff --git a/libs/cmdlib/cmdlib.cpp b/libs/cmdlib/cmdlib.cpp index 9bfd2436..075ff2c7 100644 --- a/libs/cmdlib/cmdlib.cpp +++ b/libs/cmdlib/cmdlib.cpp @@ -76,11 +76,11 @@ bool Q_Exec( const char *cmd, char *cmdline, const char *, bool, bool waitfor ){ printf( "Running system...\n" ); printf( "Command: %s\n", pCmd ); #endif - system( pCmd ); + int ret = system( pCmd ); #if GDEF_DEBUG printf( "system() returned\n" ); #endif - _exit( 0 ); + _exit( ret ); break; } return true; diff --git a/libs/picomodel/picomodel.c b/libs/picomodel/picomodel.c index 311f6de7..8a3980cb 100644 --- a/libs/picomodel/picomodel.c +++ b/libs/picomodel/picomodel.c @@ -2173,7 +2173,6 @@ int PicoRemapModel( picoModel_t *model, char *remapFile ){ } /* remap shader's ambient color */ else if ( !_pico_stricmp( p->token,"ambient" ) ) { - picoColor_t color; picoVec3_t v; /* get vector from parser */ @@ -2182,16 +2181,13 @@ int PicoRemapModel( picoModel_t *model, char *remapFile ){ } /* store as color */ - color[ 0 ] = (picoByte_t)v[ 0 ]; - color[ 1 ] = (picoByte_t)v[ 1 ]; - color[ 2 ] = (picoByte_t)v[ 2 ]; + picoColor_t color = {(picoByte_t) v[0], (picoByte_t) v[1], (picoByte_t) v[2]}; /* set new ambient color */ PicoSetShaderAmbientColor( shader,color ); } /* remap shader's diffuse color */ else if ( !_pico_stricmp( p->token,"diffuse" ) ) { - picoColor_t color; picoVec3_t v; /* get vector from parser */ @@ -2200,16 +2196,13 @@ int PicoRemapModel( picoModel_t *model, char *remapFile ){ } /* store as color */ - color[ 0 ] = (picoByte_t)v[ 0 ]; - color[ 1 ] = (picoByte_t)v[ 1 ]; - color[ 2 ] = (picoByte_t)v[ 2 ]; + picoColor_t color = {(picoByte_t) v[0], (picoByte_t) v[1], (picoByte_t) v[2]}; /* set new ambient color */ PicoSetShaderDiffuseColor( shader,color ); } /* remap shader's specular color */ else if ( !_pico_stricmp( p->token,"specular" ) ) { - picoColor_t color; picoVec3_t v; /* get vector from parser */ @@ -2218,9 +2211,7 @@ int PicoRemapModel( picoModel_t *model, char *remapFile ){ } /* store as color */ - color[ 0 ] = (picoByte_t)v[ 0 ]; - color[ 1 ] = (picoByte_t)v[ 1 ]; - color[ 2 ] = (picoByte_t)v[ 2 ]; + picoColor_t color = {(picoByte_t) v[0], (picoByte_t) v[1], (picoByte_t) v[2]}; /* set new ambient color */ PicoSetShaderSpecularColor( shader,color ); diff --git a/libs/picomodel/pm_ms3d.c b/libs/picomodel/pm_ms3d.c index 378265f3..13a5f277 100644 --- a/libs/picomodel/pm_ms3d.c +++ b/libs/picomodel/pm_ms3d.c @@ -33,6 +33,7 @@ ----------------------------------------------------------------------------- */ /* dependencies */ +#include #include "picointernal.h" #include "globaldefs.h" @@ -228,6 +229,7 @@ static picoModel_t *_ms3d_load( PM_PARAMS_LOAD ){ /* get number of vertices */ bufptr = GetWord( bufptr,&numVerts ); + assert(bufptr); ptrToVerts = bufptr; #ifdef DEBUG_PM_MS3D @@ -291,6 +293,7 @@ static picoModel_t *_ms3d_load( PM_PARAMS_LOAD ){ } /* get number of groups */ bufptr = GetWord( bufptr,&numGroups ); + assert(bufptr); // ptrToGroups = bufptr; #ifdef DEBUG_PM_MS3D @@ -332,6 +335,7 @@ static picoModel_t *_ms3d_load( PM_PARAMS_LOAD ){ /* get triangle index */ bufptr = GetWord( bufptr,(int *)&triangleIndex ); + assert(bufptr); /* get ptr to triangle data */ triangle = (TMsTriangle *)( ptrToTris + ( sizeof( TMsTriangle ) * triangleIndex ) ); @@ -376,6 +380,7 @@ static picoModel_t *_ms3d_load( PM_PARAMS_LOAD ){ } /* get number of materials */ bufptr = GetWord( bufptr,&numMaterials ); + assert(bufptr); #ifdef DEBUG_PM_MS3D printf( "NumMaterials: %d\n",numMaterials ); diff --git a/libs/profile/profile.cpp b/libs/profile/profile.cpp index c1505e07..6121d770 100644 --- a/libs/profile/profile.cpp +++ b/libs/profile/profile.cpp @@ -43,6 +43,7 @@ #include "file.h" #include +#include #include "str.h" @@ -120,7 +121,7 @@ bool save_var( const char *filename, const char *section, const char *key, const len = ftell( rc ); rewind( rc ); buf = malloc( len ); - fread( buf, len, 1, rc ); + assert(fread( buf, len, 1, rc )); old_rc.write( reinterpret_cast( buf ), len ); free( buf ); fclose( rc ); diff --git a/libs/xml/xmltextags.cpp b/libs/xml/xmltextags.cpp index 00f57a05..235029c0 100644 --- a/libs/xml/xmltextags.cpp +++ b/libs/xml/xmltextags.cpp @@ -22,6 +22,7 @@ #include "xmltextags.h" #include +#include #include "qerplugin.h" #include "stream/stringstream.h" @@ -155,6 +156,10 @@ bool XmlTagBuilder::AddShaderNode( const char* shader, TextureType textureType, break; case TEXTURE: newnode = xmlNewNode( NULL, (xmlChar*)"texture" ); + break; + default: + assert(false); + break; }; newnode = xmlDocCopyNode( newnode, doc, 1 ); diff --git a/plugins/entity/filters.cpp b/plugins/entity/filters.cpp index 15c3787a..f5ecac9a 100644 --- a/plugins/entity/filters.cpp +++ b/plugins/entity/filters.cpp @@ -26,7 +26,7 @@ #include class EntityFilterWrapper : public Filter { - bool m_active; + bool m_active = false; bool m_invert; EntityFilter &m_filter; public: diff --git a/plugins/md3model/md5.cpp b/plugins/md3model/md5.cpp index 0a548f44..63919cfb 100644 --- a/plugins/md3model/md5.cpp +++ b/plugins/md3model/md5.cpp @@ -303,7 +303,7 @@ bool MD5Model_parse(Model &model, Tokeniser &tokeniser) tokeniser.nextLine(); MD5_RETURN_FALSE_IF_FAIL(MD5_parseToken(tokeniser, "shader")); - const char *shader; + const char *shader = nullptr; MD5_RETURN_FALSE_IF_FAIL(MD5_parseString(tokeniser, shader)); surface.setShader(shader); tokeniser.nextLine(); diff --git a/plugins/shaders/shaders.cpp b/plugins/shaders/shaders.cpp index 99dac811..abf0ac9f 100644 --- a/plugins/shaders/shaders.cpp +++ b/plugins/shaders/shaders.cpp @@ -789,7 +789,7 @@ evaluateTexture(const TextureExpression &texture, const ShaderParameters ¶ms float evaluateFloat(const ShaderValue &value, const ShaderParameters ¶ms, const ShaderArguments &args) { const char *result = evaluateShaderValue(value.c_str(), params, args); - float f; + float f = 0; if (!string_parse_float(result, f)) { globalErrorStream() << "parsing float value failed: " << makeQuoted(result) << "\n"; } diff --git a/plugins/vfspk3/vfs.cpp b/plugins/vfspk3/vfs.cpp index 0829073f..171b2310 100644 --- a/plugins/vfspk3/vfs.cpp +++ b/plugins/vfspk3/vfs.cpp @@ -558,7 +558,7 @@ void InitDirectory(const char *directory, ArchiveModules &archiveModules) } const char *ext = strrchr(name, '.'); - char tmppath[PATH_MAX]; + char tmppath[PATH_MAX + 1]; if (is_dpk_vfs) { if (!!ext && !string_compare_nocase_upper(ext, ".dpkdir")) { diff --git a/radiant/brush.cpp b/radiant/brush.cpp index 57eb7af2..1255d83f 100644 --- a/radiant/brush.cpp +++ b/radiant/brush.cpp @@ -302,7 +302,7 @@ void Brush::buildBRep() class FaceFilterWrapper : public Filter { FaceFilter &m_filter; - bool m_active; + bool m_active = false; bool m_invert; public: FaceFilterWrapper(FaceFilter &filter, bool invert) : @@ -349,7 +349,7 @@ bool face_filtered(Face &face) class BrushFilterWrapper : public Filter { - bool m_active; + bool m_active = false; bool m_invert; BrushFilter &m_filter; public: diff --git a/radiant/eclass_doom3.cpp b/radiant/eclass_doom3.cpp index 247c160b..9ea8435f 100644 --- a/radiant/eclass_doom3.cpp +++ b/radiant/eclass_doom3.cpp @@ -142,7 +142,7 @@ bool EntityClassDoom3_parseUnknown(Tokeniser &tokeniser) std::size_t depth = 1; for (;;) { - const char *token; + const char *token = nullptr; PARSE_RETURN_FALSE_IF_FAIL(EntityClassDoom3_parseString(tokeniser, token)); if (string_equal(token, "}")) { if (--depth == 0) { @@ -196,7 +196,7 @@ void Model_resolveInheritance(const char *name, Model &model) bool EntityClassDoom3_parseModel(Tokeniser &tokeniser) { - const char *name; + const char *name = nullptr; PARSE_RETURN_FALSE_IF_FAIL(EntityClassDoom3_parseString(tokeniser, name)); Model &model = g_models[name]; @@ -235,7 +235,7 @@ bool EntityClassDoom3_parseModel(Tokeniser &tokeniser) PARSE_RETURN_FALSE_IF_FAIL(EntityClassDoom3_parseToken(tokeniser)); PARSE_RETURN_FALSE_IF_FAIL(EntityClassDoom3_parseToken(tokeniser, "(")); for (;;) { - const char *end; + const char *end = nullptr; PARSE_RETURN_FALSE_IF_FAIL(EntityClassDoom3_parseString(tokeniser, end)); if (string_equal(end, ")")) { tokeniser.nextLine(); @@ -245,11 +245,11 @@ bool EntityClassDoom3_parseModel(Tokeniser &tokeniser) } else if (string_equal(parameter, "anim")) { CopiedString animName; PARSE_RETURN_FALSE_IF_FAIL(EntityClassDoom3_parseString(tokeniser, animName)); - const char *animFile; + const char *animFile = nullptr; PARSE_RETURN_FALSE_IF_FAIL(EntityClassDoom3_parseString(tokeniser, animFile)); model.m_anims.insert(Model::Anims::value_type(animName, animFile)); - const char *token; + const char *token = nullptr; PARSE_RETURN_FALSE_IF_FAIL(EntityClassDoom3_parseString(tokeniser, token)); while (string_equal(token, ",")) { @@ -259,7 +259,7 @@ bool EntityClassDoom3_parseModel(Tokeniser &tokeniser) if (string_equal(token, "{")) { for (;;) { - const char *end; + const char *end = nullptr; PARSE_RETURN_FALSE_IF_FAIL(EntityClassDoom3_parseString(tokeniser, end)); if (string_equal(end, "}")) { tokeniser.nextLine(); @@ -352,14 +352,14 @@ static bool EntityClass_parse(EntityClass &entityClass, Tokeniser &tokeniser) tokeniser.nextLine(); break; } else if (string_equal(key, "model")) { - const char *token; + const char *token = nullptr; PARSE_RETURN_FALSE_IF_FAIL(EntityClassDoom3_parseString(tokeniser, token)); entityClass.fixedsize = true; StringOutputStream buffer(256); buffer << PathCleaned(token); entityClass.m_modelpath = buffer.c_str(); } else if (string_equal(key, "editor_color")) { - const char *value; + const char *value = nullptr; PARSE_RETURN_FALSE_IF_FAIL(EntityClassDoom3_parseString(tokeniser, value)); if (!string_empty(value)) { entityClass.colorSpecified = true; @@ -371,7 +371,7 @@ static bool EntityClass_parse(EntityClass &entityClass, Tokeniser &tokeniser) PARSE_RETURN_FALSE_IF_FAIL(EntityClassDoom3_parseToken(tokeniser)); } else if (string_equal(key, "editor_mins")) { entityClass.sizeSpecified = true; - const char *value; + const char *value = nullptr; PARSE_RETURN_FALSE_IF_FAIL(EntityClassDoom3_parseString(tokeniser, value)); if (!string_empty(value) && !string_equal(value, "?")) { entityClass.fixedsize = true; @@ -380,7 +380,7 @@ static bool EntityClass_parse(EntityClass &entityClass, Tokeniser &tokeniser) } } else if (string_equal(key, "editor_maxs")) { entityClass.sizeSpecified = true; - const char *value; + const char *value = nullptr; PARSE_RETURN_FALSE_IF_FAIL(EntityClassDoom3_parseString(tokeniser, value)); if (!string_empty(value) && !string_equal(value, "?")) { entityClass.fixedsize = true; @@ -456,7 +456,7 @@ static bool EntityClass_parse(EntityClass &entityClass, Tokeniser &tokeniser) } else if (string_equal(key, "inherit")) { entityClass.inheritanceResolved = false; ASSERT_MESSAGE(entityClass.m_parent.empty(), "only one 'inherit' supported per entityDef"); - const char *token; + const char *token = nullptr; PARSE_RETURN_FALSE_IF_FAIL(EntityClassDoom3_parseString(tokeniser, token)); entityClass.m_parent.push_back(token); } @@ -489,7 +489,7 @@ static bool EntityClass_parse(EntityClass &entityClass, Tokeniser &tokeniser) } EntityClassAttribute &attribute = EntityClass_insertAttribute(entityClass, key).second; attribute.m_type = "string"; - const char *value; + const char *value = nullptr; PARSE_RETURN_FALSE_IF_FAIL(EntityClassDoom3_parseString(tokeniser, value)); if (string_equal(value, "}")) { // hack for quake4 powerups.def bug globalErrorStream() << "entityDef " << makeQuoted(entityClass.m_name.c_str()) << " key " diff --git a/radiant/environment.cpp b/radiant/environment.cpp index 81face07..11a12361 100644 --- a/radiant/environment.cpp +++ b/radiant/environment.cpp @@ -197,6 +197,7 @@ bool portable_app_setup() #include #include +#include const char *LINK_NAME = #if GDEF_OS_LINUX @@ -242,10 +243,10 @@ void environment_init(int argc, char const *argv[]) // Important: must be done before calling gtk_init(). char *loginname; struct passwd *pw; - seteuid(getuid()); + assert(seteuid(getuid()) == 0); if (geteuid() == 0 && (loginname = getlogin()) != 0 && (pw = getpwnam(loginname)) != 0) { - setuid(pw->pw_uid); + assert(setuid(pw->pw_uid) == 0); } args_init(argc, argv); diff --git a/radiant/gtkdlgs.cpp b/radiant/gtkdlgs.cpp index 286bb076..2e33f9d1 100644 --- a/radiant/gtkdlgs.cpp +++ b/radiant/gtkdlgs.cpp @@ -49,6 +49,7 @@ #include #include +#include #include "os/path.h" #include "math/aabb.h" @@ -788,7 +789,7 @@ static void DoGtkTextEditor(const char *filename, guint cursorpos) void *old_filename; rewind(f); - fread(buf, 1, len, f); + assert(fread(buf, 1, len, f)); gtk_window_set_title(text_editor, filename); diff --git a/radiant/patch.cpp b/radiant/patch.cpp index c48cb44a..f4bc0b2a 100644 --- a/radiant/patch.cpp +++ b/radiant/patch.cpp @@ -2713,7 +2713,7 @@ void Patch::BuildVertexArray() class PatchFilterWrapper : public Filter { - bool m_active; + bool m_active = false; bool m_invert; PatchFilter &m_filter; public: diff --git a/radiant/points.cpp b/radiant/points.cpp index 6e29109c..3417d370 100644 --- a/radiant/points.cpp +++ b/radiant/points.cpp @@ -26,6 +26,7 @@ please contact Id Software immediately at info@idsoftware.com. */ +#include #include "points.h" #include "debugging/debugging.h" @@ -274,7 +275,7 @@ int LoadFile(const char *filename, void **bufferptr) return -1; } - fread(*bufferptr, 1, len, f); + assert(fread(*bufferptr, 1, len, f)); fclose(f); // we need to end the buffer with a 0 diff --git a/radiant/preferences.cpp b/radiant/preferences.cpp index fbd98151..5f170e0b 100644 --- a/radiant/preferences.cpp +++ b/radiant/preferences.cpp @@ -330,13 +330,14 @@ struct CGameDialog_GameFile { void CGameDialog::CreateGlobalFrame(PreferencesPage &page) { std::vector games; - games.reserve(mGames.size()); + games.reserve(mGames.size() + 1); for (std::list::iterator i = mGames.begin(); i != mGames.end(); ++i) { games.push_back((*i)->getRequiredKeyValue("name")); } + games.push_back(nullptr); page.appendCombo( "Select the game", - StringArrayRange(&(*games.begin()), &(*games.end())), + StringArrayRange(&(*games.begin()), &(*--games.end())), make_property(*this) ); page.appendCheckBox("Startup", "Show Global Preferences", m_bGamePrompt); diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 2bd7fe24..f2985e3b 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -43,6 +43,7 @@ #include #include +#include #include "generic/callback.h" #include "string/string.h" @@ -1545,6 +1546,8 @@ void XYWnd::XY_LoadBackgroundImage(const char *name) m_ix = 1; m_iy = 2; break; + default: + assert(false); } Vector3 min, max; diff --git a/tools/quake3/common/trilib.c b/tools/quake3/common/trilib.c index 5f403418..25024350 100644 --- a/tools/quake3/common/trilib.c +++ b/tools/quake3/common/trilib.c @@ -25,6 +25,7 @@ #include "globaldefs.h" #include +#include #include "cmdlib.h" #include "mathlib.h" #include "polyset.h" @@ -77,7 +78,7 @@ static void ReadPolysetGeometry( triangle_t *tripool, FILE *input, int count, tr for ( i = 0; i < count; ++i ) { int j; - fread( &tri, sizeof( tf_triangle ), 1, input ); + assert(fread( &tri, sizeof( tf_triangle ), 1, input )); ByteSwapTri( &tri ); for ( j = 0 ; j < 3 ; j++ ) { @@ -124,7 +125,7 @@ void TRI_LoadPolysets( const char *filename, polyset_t **ppPSET, int *numpsets ) iLevel = 0; - fread( &magic, sizeof( int ), 1, input ); + assert(fread( &magic, sizeof( int ), 1, input )); if ( BigLong( magic ) != MAGIC ) { Error( "%s is not a Alias object separated triangle file, magic number is wrong.", filename ); } @@ -148,7 +149,7 @@ void TRI_LoadPolysets( const char *filename, polyset_t **ppPSET, int *numpsets ) /* a file, but this does allow you to do error checking */ /* (which I'm not doing) on a per character basis. */ ++i; - fread( &( name[i] ), sizeof( char ), 1, input ); + assert(fread( &( name[i] ), sizeof( char ), 1, input )); } while ( name[i] != '\0' ); if ( i != 0 ) { @@ -161,7 +162,7 @@ void TRI_LoadPolysets( const char *filename, polyset_t **ppPSET, int *numpsets ) // indent(); // fprintf(stdout,"OBJECT START: %s\n",name); - fread( &count, sizeof( int ), 1, input ); + assert(fread( &count, sizeof( int ), 1, input )); count = BigLong( count ); ++iLevel; if ( count != 0 ) { @@ -171,7 +172,7 @@ void TRI_LoadPolysets( const char *filename, polyset_t **ppPSET, int *numpsets ) i = -1; do { ++i; - fread( &( tex[i] ), sizeof( char ), 1, input ); + assert(fread( &( tex[i] ), sizeof( char ), 1, input )); } while ( tex[i] != '\0' ); /* @@ -199,7 +200,7 @@ void TRI_LoadPolysets( const char *filename, polyset_t **ppPSET, int *numpsets ) i = -1; do { ++i; - fread( &( name[i] ), sizeof( char ), 1, input ); + assert(fread( &( name[i] ), sizeof( char ), 1, input )); } while ( name[i] != '\0' ); if ( i != 0 ) { diff --git a/tools/quake3/q3data/3dslib.c b/tools/quake3/q3data/3dslib.c index 3e37f5e4..e898dd06 100644 --- a/tools/quake3/q3data/3dslib.c +++ b/tools/quake3/q3data/3dslib.c @@ -39,7 +39,7 @@ static int ReadString( FILE *fp, char *buffer ){ do { - fread( &buffer[i], 1, sizeof( char ), fp ); + assert(fread( &buffer[i], 1, sizeof( char ), fp )); bytesRead++; } while ( buffer[i++] != 0 ); buffer[i] = 0; @@ -67,10 +67,10 @@ static void LoadMapName( FILE *fp, char *buffer, int thisChunkLen ){ switch ( chunkID ) { case _3DS_CHUNK_MAT_MAPNAME: - fread( buffer, chunkLen - 6, 1, fp ); + assert(fread( buffer, chunkLen - 6, 1, fp )); break; default: - fread( s_buffer, chunkLen - 6, 1, fp ); + assert(fread( s_buffer, chunkLen - 6, 1, fp )); break; } bytesRead += chunkLen; @@ -99,7 +99,7 @@ static void LoadMaterialList( FILE *fp, long thisChunkLen, _3DSMaterial_t *pMat switch ( chunkID ) { case _3DS_CHUNK_MAT_NAME: - fread( mat.name, chunkLen - 6, 1, fp ); + assert(fread( mat.name, chunkLen - 6, 1, fp )); if ( s_verbose ) { printf( " found mat name '%s'\n", mat.name ); } @@ -135,7 +135,7 @@ static void LoadMaterialList( FILE *fp, long thisChunkLen, _3DSMaterial_t *pMat } break; default: - fread( s_buffer, chunkLen - 6, 1, fp ); + assert(fread( s_buffer, chunkLen - 6, 1, fp )); break; } @@ -208,9 +208,9 @@ static void LoadMeshMaterialGroup( FILE *fp, long thisChunkLen, _3DSMeshMaterial ReadString( fp, mmg.name ); - fread( &mmg.numFaces, sizeof( mmg.numFaces ), 1, fp ); + assert(fread( &mmg.numFaces, sizeof( mmg.numFaces ), 1, fp )); mmg.pFaces = malloc( sizeof( mmg.pFaces[0] ) * mmg.numFaces ); - fread( mmg.pFaces, sizeof( mmg.pFaces[0] ), mmg.numFaces, fp ); + assert(fread( mmg.pFaces, sizeof( mmg.pFaces[0] ), mmg.numFaces, fp )); if ( s_verbose ) { printf( " >>> MESH MATERIAL GROUP '%s' (%d faces)\n", mmg.name, mmg.numFaces ); @@ -253,11 +253,11 @@ static void LoadNamedTriObject( FILE *fp, long thisChunkLen, _3DSTriObject_t *pT numMeshMaterialGroups++; break; case _3DS_CHUNK_FACE_ARRAY: - fread( &triObj.numFaces, sizeof( triObj.numFaces ), 1, fp ); + assert(fread( &triObj.numFaces, sizeof( triObj.numFaces ), 1, fp )); assert( triObj.pFaces == 0 ); triObj.pFaces = malloc( sizeof( triObj.pFaces[0] ) * triObj.numFaces ); - fread( triObj.pFaces, sizeof( triObj.pFaces[0] ), triObj.numFaces, fp ); + assert(fread( triObj.pFaces, sizeof( triObj.pFaces[0] ), triObj.numFaces, fp )); bytesRead += sizeof( triObj.numFaces ) + triObj.numFaces * sizeof( triObj.pFaces[0] ) + 6; if ( s_verbose ) { @@ -270,9 +270,9 @@ static void LoadNamedTriObject( FILE *fp, long thisChunkLen, _3DSTriObject_t *pT break; case _3DS_CHUNK_POINT_ARRAY: - fread( &triObj.numPoints, sizeof( triObj.numPoints ), 1, fp ); + assert(fread( &triObj.numPoints, sizeof( triObj.numPoints ), 1, fp )); triObj.pPoints = malloc( sizeof( triObj.pPoints[0] ) * triObj.numPoints ); - fread( triObj.pPoints, sizeof( triObj.pPoints[0] ), triObj.numPoints, fp ); + assert(fread( triObj.pPoints, sizeof( triObj.pPoints[0] ), triObj.numPoints, fp )); bytesRead += sizeof( triObj.numPoints ) + triObj.numPoints * sizeof( triObj.pPoints[0] ) + 6; // flip points around into our coordinate system @@ -298,9 +298,9 @@ static void LoadNamedTriObject( FILE *fp, long thisChunkLen, _3DSTriObject_t *pT } break; case _3DS_CHUNK_TEX_VERTS: - fread( &triObj.numTexVerts, sizeof( triObj.numTexVerts ), 1, fp ); + assert(fread( &triObj.numTexVerts, sizeof( triObj.numTexVerts ), 1, fp )); triObj.pTexVerts = malloc( sizeof( triObj.pTexVerts[0] ) * triObj.numTexVerts ); - fread( triObj.pTexVerts, sizeof( triObj.pTexVerts[0] ), triObj.numTexVerts, fp ); + assert(fread( triObj.pTexVerts, sizeof( triObj.pTexVerts[0] ), triObj.numTexVerts, fp )); bytesRead += sizeof( triObj.numTexVerts ) + sizeof( triObj.pTexVerts[0] ) * triObj.numTexVerts + 6; if ( s_verbose ) { @@ -312,7 +312,7 @@ static void LoadNamedTriObject( FILE *fp, long thisChunkLen, _3DSTriObject_t *pT } break; default: - fread( s_buffer, chunkLen - 6, 1, fp ); + assert(fread( s_buffer, chunkLen - 6, 1, fp )); bytesRead += chunkLen; break; } @@ -371,7 +371,7 @@ static void LoadNamedObject( FILE *fp, long thisChunkLen, _3DSNamedObject_t *pNO numTriObjects++; break; default: - fread( s_buffer, chunkLen - 6, 1, fp ); + assert(fread( s_buffer, chunkLen - 6, 1, fp )); break; } @@ -423,7 +423,7 @@ static void LoadEditChunk( FILE *fp, long thisChunkLen, _3DSEditChunk_t *pEC ){ break; case _3DS_CHUNK_MESH_VERSION: default: - fread( s_buffer, chunkLen - 6, 1, fp ); + assert(fread( s_buffer, chunkLen - 6, 1, fp )); break; } @@ -485,10 +485,10 @@ static void Load3DS( const char *filename, _3DS_t *p3DS, qboolean verbose ){ LoadEditChunk( fp, chunkLen - 6, &editChunk ); break; case _3DS_CHUNK_KEYFRAME_DATA: - fread( s_buffer, chunkLen - 6, 1, fp ); + assert(fread( s_buffer, chunkLen - 6, 1, fp )); break; default: - fread( s_buffer, chunkLen - 6, 1, fp ); + assert(fread( s_buffer, chunkLen - 6, 1, fp )); break; } } diff --git a/tools/quake3/q3data/md3lib.c b/tools/quake3/q3data/md3lib.c index 93b1dfe0..ead6df21 100644 --- a/tools/quake3/q3data/md3lib.c +++ b/tools/quake3/q3data/md3lib.c @@ -85,6 +85,9 @@ void MD3_ComputeTagFromTri( md3Tag_t *pTag, float pTri[3][3] ){ hypotSide = 2; origin = 1; } + else { + assert(0); + } len[hypotSide] = -1; if ( len[0] > len[1] && len[0] > len[2] ) { @@ -96,6 +99,9 @@ void MD3_ComputeTagFromTri( md3Tag_t *pTag, float pTri[3][3] ){ else if ( len[2] > len[0] && len[2] > len[1] ) { longestSide = 2; } + else { + assert(0); + } len[longestSide] = -1; if ( len[0] > len[1] && len[0] > len[2] ) { @@ -107,6 +113,9 @@ void MD3_ComputeTagFromTri( md3Tag_t *pTag, float pTri[3][3] ){ else if ( len[2] > len[0] && len[2] > len[1] ) { shortestSide = 2; } + else { + assert(0); + } len[shortestSide] = -1; @@ -154,7 +163,7 @@ void MD3_Dump( const char *filename ){ fileSize = filelength( fp ); _buffer = malloc( fileSize ); - fread( _buffer, fileSize, 1, fp ); + assert(fread( _buffer, fileSize, 1, fp )); fclose( fp ); buffer = ( char * ) _buffer; diff --git a/tools/quake3/q3data/video.c b/tools/quake3/q3data/video.c index 2fa7cee2..8de263bc 100644 --- a/tools/quake3/q3data/video.c +++ b/tools/quake3/q3data/video.c @@ -249,7 +249,7 @@ void LoadSoundtrack( void ){ } len = Q_filelength( f ); s_soundtrack = malloc( len ); - fread( s_soundtrack, 1, len, f ); + assert(fread( s_soundtrack, 1, len, f )); fclose( f ); s_wavinfo = GetWavinfo( name, s_soundtrack, len ); diff --git a/tools/quake3/q3map2/bsp.c b/tools/quake3/q3map2/bsp.c index bbab3f25..8553e465 100644 --- a/tools/quake3/q3map2/bsp.c +++ b/tools/quake3/q3map2/bsp.c @@ -127,7 +127,7 @@ static void ProcessAdvertisements( void ) { static void SetCloneModelNumbers( void ){ int i, j; int models; - char modelValue[ 10 ]; + char modelValue[ 12 ]; const char *value, *value2, *value3; diff --git a/tools/quake3/q3map2/convert_bsp.c b/tools/quake3/q3map2/convert_bsp.c index b7dfeffd..de3f8fd9 100644 --- a/tools/quake3/q3map2/convert_bsp.c +++ b/tools/quake3/q3map2/convert_bsp.c @@ -39,7 +39,7 @@ */ void PseudoCompileBSP( qboolean need_tree, const char *BSPFilePath, const char *surfaceFilePath ){ int models; - char modelValue[10]; + char modelValue[12]; entity_t *entity; face_t *faces; tree_t *tree; diff --git a/tools/quake3/q3map2/light_bounce.c b/tools/quake3/q3map2/light_bounce.c index 9fe00ef6..bf2b63e5 100644 --- a/tools/quake3/q3map2/light_bounce.c +++ b/tools/quake3/q3map2/light_bounce.c @@ -288,7 +288,7 @@ static void RadSample( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm, /* multiply by texture color */ if ( !RadSampleImage( si->lightImage->pixels, si->lightImage->width, si->lightImage->height, rw->verts[ samples ].st, textureColor ) ) { VectorCopy( si->averageColor, textureColor ); - textureColor[ 4 ] = 255.0f; + textureColor[ 3 ] = 255.0f; } for ( i = 0; i < 3; i++ ) color[ i ] = ( textureColor[ i ] / 255 ) * ( rw->verts[ samples ].color[ lightmapNum ][ i ] / 255.0f ); @@ -372,7 +372,7 @@ static void RadSample( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm, /* multiply by texture color */ if ( !RadSampleImage( si->lightImage->pixels, si->lightImage->width, si->lightImage->height, st, textureColor ) ) { VectorCopy( si->averageColor, textureColor ); - textureColor[ 4 ] = 255; + textureColor[ 3 ] = 255; } for ( i = 0; i < 3; i++ ) color[ i ] = ( textureColor[ i ] / 255 ) * ( radLuxel[ i ] / 255 ); diff --git a/tools/quake3/q3map2/light_ydnar.c b/tools/quake3/q3map2/light_ydnar.c index c75dac2e..3e5b52fb 100644 --- a/tools/quake3/q3map2/light_ydnar.c +++ b/tools/quake3/q3map2/light_ydnar.c @@ -34,6 +34,7 @@ /* dependencies */ +#include #include "q3map2.h" @@ -1742,9 +1743,10 @@ static qboolean SubmapRawLuxel( rawLightmap_t *lm, int x, int y, float bx, float } else { Sys_FPrintf( SYS_WRN, "WARNING: Spurious lightmap S vector\n" ); + assert(0); } - VectorSubtract( origin2, origin, originVecs[ 0 ] ); + VectorSubtract(origin2, origin, originVecs[0]); //% VectorSubtract( normal2, normal, normalVecs[ 0 ] ); /* calulate y vector */ @@ -1766,6 +1768,7 @@ static qboolean SubmapRawLuxel( rawLightmap_t *lm, int x, int y, float bx, float } else { Sys_FPrintf( SYS_WRN, "WARNING: Spurious lightmap T vector\n" ); + assert(0); } VectorSubtract( origin2, origin, originVecs[ 1 ] ); diff --git a/tools/quake3/q3map2/portals.c b/tools/quake3/q3map2/portals.c index 676fa315..4d5295a3 100644 --- a/tools/quake3/q3map2/portals.c +++ b/tools/quake3/q3map2/portals.c @@ -669,7 +669,7 @@ int FloodEntities( tree_t *tree ){ node_t *headnode; entity_t *e, *tripped; const char *value; - int tripcount; + int tripcount = 0; headnode = tree->headnode; diff --git a/tools/quake3/q3map2/shaders.c b/tools/quake3/q3map2/shaders.c index 166319aa..d9fd98f6 100644 --- a/tools/quake3/q3map2/shaders.c +++ b/tools/quake3/q3map2/shaders.c @@ -34,6 +34,7 @@ /* dependencies */ +#include #include "q3map2.h" @@ -719,7 +720,7 @@ void FinishShader( shaderInfo_t *si ){ /* determine error squared */ VectorSubtract( color, si->averageColor, delta ); - delta[ 3 ] = color[ 3 ] - si->averageColor[ 3 ]; + delta[ 3 ] = color[ 3 ] - 255; dist = delta[ 0 ] * delta[ 0 ] + delta[ 1 ] * delta[ 1 ] + delta[ 2 ] * delta[ 2 ] + delta[ 3 ] * delta[ 3 ]; if ( dist < bestDist ) { si->stFlat[ 0 ] = st[ 0 ]; @@ -956,8 +957,10 @@ void Parse1DMatrixAppend( char *buffer, int x, vec_t *m ){ } } - - +#define snprintf_ignore(s, n, format, ...) do { \ + size_t __n = snprintf(s, n, format, __VA_ARGS__); \ + if (__n >= n) { assert(0); } /* truncated, ignore */ \ +} while (0) /* ParseShaderFile() @@ -1185,7 +1188,7 @@ static void ParseShaderFile( const char *filename ){ si->implicitMap = IM_OPAQUE; GetTokenAppend( shaderText, qfalse ); if ( token[ 0 ] == '-' && token[ 1 ] == '\0' ) { - sprintf( si->implicitImagePath, "%s.tga", si->shader ); + snprintf_ignore( si->implicitImagePath, sizeof si->implicitImagePath, "%s.tga", si->shader ); } else{ strcpy( si->implicitImagePath, token ); @@ -1196,7 +1199,7 @@ static void ParseShaderFile( const char *filename ){ si->implicitMap = IM_MASKED; GetTokenAppend( shaderText, qfalse ); if ( token[ 0 ] == '-' && token[ 1 ] == '\0' ) { - sprintf( si->implicitImagePath, "%s.tga", si->shader ); + snprintf_ignore( si->implicitImagePath, sizeof si->implicitImagePath, "%s.tga", si->shader ); } else{ strcpy( si->implicitImagePath, token ); @@ -1207,7 +1210,7 @@ static void ParseShaderFile( const char *filename ){ si->implicitMap = IM_MASKED; GetTokenAppend( shaderText, qfalse ); if ( token[ 0 ] == '-' && token[ 1 ] == '\0' ) { - sprintf( si->implicitImagePath, "%s.tga", si->shader ); + snprintf_ignore( si->implicitImagePath, sizeof si->implicitImagePath, "%s.tga", si->shader ); } else{ strcpy( si->implicitImagePath, token ); @@ -1251,7 +1254,7 @@ static void ParseShaderFile( const char *filename ){ /* use top image as sky light image */ if ( si->lightImagePath[ 0 ] == '\0' ) { - sprintf( si->lightImagePath, "%s_up.tga", si->skyParmsImageBase ); + snprintf_ignore( si->lightImagePath, sizeof si->lightImagePath, "%s_up.tga", si->skyParmsImageBase ); } } diff --git a/tools/quake3/q3map2/surface.c b/tools/quake3/q3map2/surface.c index a51db8c1..5f1c92dd 100644 --- a/tools/quake3/q3map2/surface.c +++ b/tools/quake3/q3map2/surface.c @@ -34,6 +34,7 @@ /* dependencies */ +#include #include "q3map2.h" @@ -783,7 +784,7 @@ byte GetShaderIndexForPoint( indexMap_t *im, vec3_t eMins, vec3_t eMaxs, vec3_t #define snprintf_ignore(s, n, format, ...) do { \ size_t __n = snprintf(s, n, format, __VA_ARGS__); \ - if (n >= n) {} /* truncated, ignore */ \ + if (__n >= n) { assert(0); } /* truncated, ignore */ \ } while (0) /* diff --git a/tools/quake3/q3map2/surface_meta.c b/tools/quake3/q3map2/surface_meta.c index 145e1961..4fff8a74 100644 --- a/tools/quake3/q3map2/surface_meta.c +++ b/tools/quake3/q3map2/surface_meta.c @@ -987,8 +987,7 @@ void CreateEdge( vec4_t plane, vec3_t a, vec3_t b, edge_t *edge ){ edge->kingpinLength = edge->edge[ edge->kingpin ]; VectorNormalize( edge->edge, edge->edge ); - edge->edge[ 3 ] = DotProduct( a, edge->edge ); - edge->length = DotProduct( b, edge->edge ) - edge->edge[ 3 ]; + edge->length = DotProduct( b, edge->edge ) - DotProduct( a, edge->edge ); /* create perpendicular plane that edge lies in */ CrossProduct( plane, edge->edge, edge->plane ); diff --git a/tools/quake3/q3map2/writebsp.c b/tools/quake3/q3map2/writebsp.c index 4b3e53fe..3878d22f 100644 --- a/tools/quake3/q3map2/writebsp.c +++ b/tools/quake3/q3map2/writebsp.c @@ -254,7 +254,7 @@ int EmitDrawNode_r( node_t *node ){ void SetModelNumbers( void ){ int i; int models; - char value[10]; + char value[12]; models = 1; for ( i = 1 ; i < numEntities ; i++ ) {