]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
gcc: appease the hardening warnings TimePath/gcc
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 6 May 2018 10:51:40 +0000 (20:51 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 6 May 2018 10:51:40 +0000 (20:51 +1000)
39 files changed:
CMakeLists.txt
contrib/bobtoolz/DTrainDrawer.cpp
contrib/bobtoolz/DTreePlanter.h
contrib/bobtoolz/bsploader.cpp
contrib/bobtoolz/cportals.cpp
contrib/bobtoolz/lists.cpp
contrib/bobtoolz/misc.cpp
contrib/prtview/portals.cpp
libs/bytestreamutils.h
libs/cmdlib/cmdlib.cpp
libs/picomodel/picomodel.c
libs/picomodel/pm_ms3d.c
libs/profile/profile.cpp
libs/xml/xmltextags.cpp
plugins/entity/filters.cpp
plugins/md3model/md5.cpp
plugins/shaders/shaders.cpp
plugins/vfspk3/vfs.cpp
radiant/brush.cpp
radiant/eclass_doom3.cpp
radiant/environment.cpp
radiant/gtkdlgs.cpp
radiant/patch.cpp
radiant/points.cpp
radiant/preferences.cpp
radiant/xywindow.cpp
tools/quake3/common/trilib.c
tools/quake3/q3data/3dslib.c
tools/quake3/q3data/md3lib.c
tools/quake3/q3data/video.c
tools/quake3/q3map2/bsp.c
tools/quake3/q3map2/convert_bsp.c
tools/quake3/q3map2/light_bounce.c
tools/quake3/q3map2/light_ydnar.c
tools/quake3/q3map2/portals.c
tools/quake3/q3map2/shaders.c
tools/quake3/q3map2/surface.c
tools/quake3/q3map2/surface_meta.c
tools/quake3/q3map2/writebsp.c

index aa1028d64d869b1efb61341377dbf72a37e96cd9..95fa439ffb73caffebf04c360fea956ffd201766 100644 (file)
@@ -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 ()
index 0a3307de978da70294afa257732e591c5c1424cd..0165fa08bd74b38202dd72440af80b40bbc3a30d 100644 (file)
@@ -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);
index 5d6612320c5d07360a8f97712afb89c6233b26e7..3b38c5e630cf3ac338a0870dfa70249bf513376f 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef __DTREE_H__
 #define __DTREE_H__
 
+#include <cassert>
 #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);
index 020cf4d8d774bdb846e192b351f7ab3c72066bde..a4e74031171021570b60bacf39e7c38e2eb4defc 100644 (file)
@@ -1,4 +1,5 @@
 #include <globaldefs.h>
+#include <cassert>
 #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;
index ab944ed82514bb57f59681d65417694e6111c405..3fd39202f4bfa6660dfb9f7164b7a788261dfe38 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <string.h>
 #include <math.h>
+#include <cassert>
 
 #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++) {
index 9830c3764134fee7ae7b86d4d0e5ad4a4a2640f8..d9e5cbed02d3b931b9a72716f4e816b854f9b4a4 100644 (file)
@@ -34,9 +34,7 @@ bool LoadExclusionList(char *filename, std::list<Str> *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);
index 95274655b9c5b466b67c62f2b090d89f643bb1e2..9e6c2b8b980daecff410d98ffcdc0490360e4496 100644 (file)
@@ -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;
index c4d3b04d57b95e015b096c5c8b6ec1a17ac4568d..eb14f1d4c776109cc6eac83dc57d525d119dfb57 100644 (file)
@@ -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);
index 69ec3755f9c0ca1da77eecc976f53f2d0f7d55d4..45749ce02d39e0cc08df1d9261a969eeba2e5eea 100644 (file)
@@ -151,7 +151,7 @@ inline float istream_read_float32_be( InputStreamType& istream ){
 
 template<typename InputStreamType>
 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;
 }
index 9bfd24364dc4bff37e09a5354b10f3070cf7d364..075ff2c7d45c0a6c80021ad8c1a889afe0aa0a69 100644 (file)
@@ -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;
index 311f6de760c7791bb9e94f717d481a192c46dfdc..8a3980cb37c1988790b3bf1f725a20b8b2ee6439 100644 (file)
@@ -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 );
index 378265f30a5504d59206c95b08d6f43fb103bce7..13a5f277f39d0a350cae8b3f997b9e80bd594f4f 100644 (file)
@@ -33,6 +33,7 @@
    ----------------------------------------------------------------------------- */
 
 /* dependencies */
+#include <assert.h>
 #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 );
index c1505e073b15ac1c2b68fbf58a5fd92568dbe11e..6121d77009c1f503f408e08366c2de0965f7a616 100644 (file)
@@ -43,6 +43,7 @@
 #include "file.h"
 
 #include <stdlib.h>
+#include <cassert>
 
 #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<MemStream::byte_type*>( buf ), len );
                free( buf );
                fclose( rc );
index 00f57a057ac2337eec22fa81e6e8bd247793fbf3..235029c0c7394fd2461207b379617d56fd6d59c4 100644 (file)
@@ -22,6 +22,7 @@
 #include "xmltextags.h"
 
 #include <string>
+#include <cassert>
 
 #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 );
index 15c3787a2834be33981627a668d945fac04fce75..f5ecac9a48b5cd0ebe42cf6758b14d14df852e46 100644 (file)
@@ -26,7 +26,7 @@
 #include <list>
 
 class EntityFilterWrapper : public Filter {
-    bool m_active;
+    bool m_active = false;
     bool m_invert;
     EntityFilter &m_filter;
 public:
index 0a548f44384fec1fadc9fa37a53d8d7e023a21c6..63919cfb8ed574a582fb884dfc0c20e37766a82c 100644 (file)
@@ -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();
index 99dac811d9a4baf2ff882d1b8876ff04ad7abd61..abf0ac9fa82a18462c909fa90672ae361270c2f9 100644 (file)
@@ -789,7 +789,7 @@ evaluateTexture(const TextureExpression &texture, const ShaderParameters &params
 float evaluateFloat(const ShaderValue &value, const ShaderParameters &params, 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";
     }
index 0829073f78b1be186fb2c90e8dd1aa7a162fc099..171b2310707fe142a326ecd75fe612e0283e7a31 100644 (file)
@@ -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")) {
index 57eb7af26bef29be790a238c26c7129996bb88ed..1255d83fe23d46654751d5827f4b59f75764c40b 100644 (file)
@@ -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:
index 247c160bb3e3c7185938c1f2952bbbee4cac41bb..9ea8435f59b97d9595549965d5a73eb393468267 100644 (file)
@@ -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 "
index 81face071e0409eff7b07776f211ddb79ed3f326..11a123614fe7ad071ae12115c93a740d411c81bb 100644 (file)
@@ -197,6 +197,7 @@ bool portable_app_setup()
 #include <unistd.h>
 
 #include <glib.h>
+#include <cassert>
 
 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);
index 286bb0765db7c4439037da18ec0f90fa58f90cbf..2e33f9d1f3e0c2540043b2314ce1d115ae680bb6 100644 (file)
@@ -49,6 +49,7 @@
 
 #include <gdk/gdkkeysyms.h>
 #include <uilib/uilib.h>
+#include <cassert>
 
 #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);
 
index c48cb44a4fa522929e9a53921d2deaa324c227ea..f4bc0b2a873494012b9732d62ae01b485f1da808 100644 (file)
@@ -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:
index 6e29109c845b314e6bce182a01a90f39c0055daa..3417d37009987896d1a8d9338c8220734d3fb74d 100644 (file)
@@ -26,6 +26,7 @@
    please contact Id Software immediately at info@idsoftware.com.
  */
 
+#include <cassert>
 #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
index fbd9815169fb935bc5bcea1b316638e47eab80ed..5f170e0b704435348d0e3f4c8a9cb296978b261f 100644 (file)
@@ -330,13 +330,14 @@ struct CGameDialog_GameFile {
 void CGameDialog::CreateGlobalFrame(PreferencesPage &page)
 {
     std::vector<const char *> games;
-    games.reserve(mGames.size());
+    games.reserve(mGames.size() + 1);
     for (std::list<CGameDescription *>::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<CGameDialog_GameFile>(*this)
     );
     page.appendCheckBox("Startup", "Show Global Preferences", m_bGamePrompt);
index 2bd7fe24aa56f9f12397b8c226ee77d7f1c82292..f2985e3b11db014d4e62597b3032d58336abef00 100644 (file)
@@ -43,6 +43,7 @@
 
 #include <uilib/uilib.h>
 #include <gdk/gdkkeysyms.h>
+#include <cassert>
 
 #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;
index 5f403418ff449077f8c7a2f1a83d5451ac0b4278..250243503443f7846c78de8c48952d9f66173873 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "globaldefs.h"
 #include <stdio.h>
+#include <assert.h>
 #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 ) {
index 3e37f5e4b7217e15c9193849610c1e156fc86c65..e898dd06fd8c5cff5fc131aa7a9ea1f65495c837 100644 (file)
@@ -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;
                }
        }
index 93b1dfe0028787d2a015149839f62ca7788c54df..ead6df21397feb4d10ad69f9773a2e2a16a57ba2 100644 (file)
@@ -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;
index 2fa7cee2ca14d2e6120389fe22149b9317273848..8de263bc4c4e3285d160c27fc01febd2c98b96ab 100644 (file)
@@ -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 );
index bbab3f25ee101fa57b3db1955a4b2330a4421649..8553e4651d504fe0892b70b30af12329d8dbc15c 100644 (file)
@@ -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;
 
 
index b7dfeffd893acc77b90412a77af75800cd6d55eb..de3f8fd92143343837f63057292b1a90cbbcb175 100644 (file)
@@ -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;
index 9fe00ef68c57dd7d7f5876739be47d86fd0eeffa..bf2b63e5293e24cec76eb25dc635e253f786fd5c 100644 (file)
@@ -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 );
index c75dac2e55f5705029df32059d2eec071a09031d..3e5b52fb78d3d9873757a163a8c64e744b0370d8 100644 (file)
@@ -34,6 +34,7 @@
 
 
 /* dependencies */
+#include <assert.h>
 #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 ] );
index 676fa31599df4754276c9580b5e532edd709912c..4d5295a3e5e42d04d6dd1ef35e8733237fd9855f 100644 (file)
@@ -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;
index 166319aa930862279da2abee60d3f9c0d9176969..d9fd98f65c48d479301c9b08685bfb67b4fd48af 100644 (file)
@@ -34,6 +34,7 @@
 
 
 /* dependencies */
+#include <assert.h>
 #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 );
                                        }
                                }
 
index a51db8c176c7e91f59c67e183da6db59bcc3f137..5f1c92dd32237dfed0d5b3244569ce33737459ff 100644 (file)
@@ -34,6 +34,7 @@
 
 
 /* dependencies */
+#include <assert.h>
 #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)
 
 /*
index 145e1961cc7ee683fcd89814fdddcbc6e61ec6ad..4fff8a7403b836970afee3e16cb33bc732e7647e 100644 (file)
@@ -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 );
index 4b3e53fe8ce4baaf83cb599da3df60fbcc3511c8..3878d22f9c26f67b080433b8257c7faac091e4ec 100644 (file)
@@ -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++ ) {