Klockwork (http://www.klocwork.com) report; game engine fixes, related to 'Use Blende...
authorCharlie Carley <snailrose@gmail.com>
Sun, 21 Jan 2007 04:45:44 +0000 (04:45 +0000)
committerCharlie Carley <snailrose@gmail.com>
Sun, 21 Jan 2007 04:45:44 +0000 (04:45 +0000)
/source/gameengine/Ketsji/BL_Material.cpp;16;18;Critical;1;
/source/gameengine/Ketsji/BL_Shader.cpp;293;30;Critical;1;
/source/gameengine/Ketsji/BL_Shader.cpp;314;30;Critical;1;
/source/gameengine/Ketsji/BL_Shader.cpp;341;30;Critical;1;
/source/gameengine/Ketsji/BL_Shader.cpp;1264;40;Critical;1;
/source/gameengine/Ketsji/BL_Shader.cpp;1194;40;Critical;1;
/source/gameengine/Ketsji/BL_Shader.cpp;916;30;Critical;1;
/source/gameengine/Ketsji/KX_BlenderMaterial.cpp;257;24;Critical;1;
/source/gameengine/Ketsji/KX_BlenderMaterial.cpp;262;24;Critical;1;
/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.cpp;195;24;Error;3;
/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp;1209;16;Critical;1;

source/gameengine/Ketsji/BL_Material.cpp
source/gameengine/Ketsji/BL_Shader.cpp
source/gameengine/Ketsji/KX_BlenderMaterial.cpp
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.cpp
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp

index a8d80ef6224f279a2a3d8515b31e804577e3a93f..7ed2da590a90bb8984d4baea780008b5be228658 100644 (file)
@@ -11,7 +11,7 @@ MTex* getImageFromMaterial(Material *mat, int index)
 {
        if(!mat) return 0;
        
-       if(!(index >=0 && index <=10) ) return 0;
+       if(!(index >=0 && index < MAX_MTEX) ) return 0;
        
        MTex *m = mat->mtex[index];
        return m?m:0;
index ce0809628ce0725719666b70bc1851e740b1194e..4e32d2cced9273d528d5d9acd12cb9664665cceb 100644 (file)
@@ -30,6 +30,7 @@
 
 #define SORT_UNIFORMS 1
 #define UNIFORM_MAX_LEN sizeof(float)*16
+#define MAX_LOG_LEN 262144 // bounds
 
 BL_Uniform::BL_Uniform(int data_size)
 :      mLoc(-1),
@@ -265,6 +266,7 @@ bool BL_Shader::LinkProgram()
        int vertstatus=0, fragstatus=0, progstatus=0;
        unsigned int tmpVert=0, tmpFrag=0, tmpProg=0;
        int char_len=0;
+       char *logInf =0;
 
        if(mError)
                goto programError;
@@ -289,14 +291,15 @@ bool BL_Shader::LinkProgram()
        bgl::blGetObjectParameterivARB(tmpVert, GL_OBJECT_INFO_LOG_LENGTH_ARB,(GLint*) &vertlen);
        
        // print info if any
-       if( vertlen > 0){
-               STR_String str("",vertlen);
-               bgl::blGetInfoLogARB(tmpVert, vertlen, (GLsizei*)&char_len, str.Ptr());
+       if( vertlen > 0 && vertlen < MAX_LOG_LEN){
+               logInf = (char*)MEM_mallocN(vertlen, "vert-log");
+               bgl::blGetInfoLogARB(tmpVert, vertlen, (GLsizei*)&char_len, logInf);
                if(char_len >0) {
                        spit("---- Vertex Shader Error ----");
-                       spit(str.ReadPtr());
+                       spit(logInf);
                }
-               str.Clear();
+               MEM_freeN(logInf);
+               logInf=0;
        }
        // check for compile errors
        bgl::blGetObjectParameterivARB(tmpVert, GL_OBJECT_COMPILE_STATUS_ARB,(GLint*)&vertstatus);
@@ -310,14 +313,15 @@ bool BL_Shader::LinkProgram()
        bgl::blShaderSourceARB(tmpFrag, 1,(const char**)&fragProg, 0);
        bgl::blCompileShaderARB(tmpFrag);
        bgl::blGetObjectParameterivARB(tmpFrag, GL_OBJECT_INFO_LOG_LENGTH_ARB, (GLint*) &fraglen);
-       if(fraglen >0 ){
-               STR_String str("",fraglen);
-               bgl::blGetInfoLogARB(tmpFrag, fraglen,(GLsizei*) &char_len, str.Ptr());
+       if(fraglen >0 && fraglen < MAX_LOG_LEN){
+               logInf = (char*)MEM_mallocN(fraglen, "frag-log");
+               bgl::blGetInfoLogARB(tmpFrag, fraglen,(GLsizei*) &char_len, logInf);
                if(char_len >0) {
                        spit("---- Fragment Shader Error ----");
-                       spit(str.ReadPtr());
+                       spit(logInf);
                }
-               str.Clear();
+               MEM_freeN(logInf);
+               logInf=0;
        }
 
        bgl::blGetObjectParameterivARB(tmpFrag, GL_OBJECT_COMPILE_STATUS_ARB, (GLint*) &fragstatus);
@@ -337,14 +341,15 @@ bool BL_Shader::LinkProgram()
        bgl::blGetObjectParameterivARB(tmpProg, GL_OBJECT_LINK_STATUS_ARB, (GLint*) &progstatus);
        
 
-       if(proglen > 0) {
-               STR_String str("",proglen);
-               bgl::blGetInfoLogARB(tmpProg, proglen, (GLsizei*)&char_len, str.Ptr());
+       if(proglen > 0 && proglen < MAX_LOG_LEN) {
+               logInf = (char*)MEM_mallocN(proglen, "prog-log");
+               bgl::blGetInfoLogARB(tmpProg, proglen, (GLsizei*)&char_len, logInf);
                if(char_len >0) {
                        spit("---- GLSL Program ----");
-                       spit(str.ReadPtr());
+                       spit(logInf);
                }
-               str.Clear();
+               MEM_freeN(logInf);
+               logInf=0;
        }
 
        if(!progstatus){
@@ -911,15 +916,18 @@ KX_PYMETHODDEF_DOC( BL_Shader, validate, "validate()")
        bgl::blValidateProgramARB(mShader);
        bgl::blGetObjectParameterivARB(mShader, GL_OBJECT_VALIDATE_STATUS_ARB,(GLint*) &stat);
 
-       if(stat > 0) {
+
+       if(stat > 0 && stat < MAX_LOG_LEN) {
                int char_len=0;
-               STR_String str("",stat);
-               bgl::blGetInfoLogARB(mShader, stat,(GLsizei*) &char_len, str.Ptr());
+               char *logInf = (char*)MEM_mallocN(stat, "validate-log");
+
+               bgl::blGetInfoLogARB(mShader, stat,(GLsizei*) &char_len, logInf);
                if(char_len >0) {
                        spit("---- GLSL Validation ----");
-                       spit(str.ReadPtr());
+                       spit(logInf);
                }
-               str.Clear();
+               MEM_freeN(logInf);
+               logInf=0;
        }
 #endif//GL_ARB_shader_objects
        Py_Return;
@@ -1188,7 +1196,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformfv , "setUniformfv( float (list2 or lis
                        {
                                unsigned int list_size = PySequence_Size(listPtr);
                                
-                               for(unsigned int i=0; (i<list_size && i<=4); i++)
+                               for(unsigned int i=0; (i<list_size && i<4); i++)
                                {
                                        PyObject *item = PySequence_GetItem(listPtr, i);
                                        array_data[i] = (float)PyFloat_AsDouble(item);
@@ -1258,7 +1266,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformiv, "setUniformiv( int (list2 or list3
                        {
                                unsigned int list_size = PySequence_Size(listPtr);
                                
-                               for(unsigned int i=0; (i<list_size && i<=4); i++)
+                               for(unsigned int i=0; (i<list_size && i<4); i++)
                                {
                                        PyObject *item = PySequence_GetItem(listPtr, i);
                                        array_data[i] = PyInt_AsLong(item);
index 426a3a1aab5279fab84a0f34a55068b05bc8f9b5..fa1c67f251ca6c8a2e2bc98ffddddef223539297 100644 (file)
@@ -245,7 +245,7 @@ void KX_BlenderMaterial::setTexData( bool enable, RAS_IRasterizer *ras)
        }
 
        int mode = 0,i=0;
-       for(i=0; (i<mMaterial->num_enabled); i++) {
+       for(i=0; (i<mMaterial->num_enabled && i<MAXTEX); i++) {
                if( !mTextures[i].Ok() ) continue;
 
                mTextures[i].ActivateTexture();
index b609c85dcbeed9823e1ae97cd7950fdf1b21915c..8014c4ebd2ac4102202493aeb7f00d68aaad00f4 100644 (file)
@@ -192,15 +192,18 @@ static void bglInitEntryPoints (void)
                if (!libGL)
                {
                        libGL = dlopen("libGL.so", RTLD_GLOBAL);
-                       bglGetProcAddress = (PFNBGLXGETPROCADDRESSARBPROC) (dlsym(libGL, "glXGetProcAddressARB"));
+                       if (libGL)
+                               bglGetProcAddress = (PFNBGLXGETPROCADDRESSARBPROC) (dlsym(libGL, "glXGetProcAddressARB"));
+                       else
+                               std::cout << "Error: " << dlerror() << std::endl;
 
                        // dlclose(libGL);
                        if (!bglGetProcAddress)
                                bglGetProcAddress = (PFNBGLXGETPROCADDRESSARBPROC) _getProcAddress;
                        
                        // --
-                       if( !libGL && !bglGetProcAddress)
-                               std::cout << "Error: " << dlerror() << std::endl;
+                       if(!bglGetProcAddress)
+                               std::cout << "Error: unable to find _getProcAddress in libGL" << std::endl;
                }
        }
 }
index e90411e05e81db50ecfb06de037e7562b6a5bc0d..53ec7a02e6f79043196c9407b96ab5ca983265b0 100644 (file)
@@ -1205,7 +1205,7 @@ void RAS_OpenGLRasterizer::IndexPrimitives_3DText(const vecVertexArray & vertexa
 void RAS_OpenGLRasterizer::SetTexCoords(TexCoGen coords,int unit)
 {
        // this changes from material to material
-       if(unit <= RAS_MAX)
+       if(unit < RAS_MAX)
                m_texco[unit] = coords;
 }