diff options
author | Charlie Carley <snailrose@gmail.com> | 2007-01-21 07:45:44 +0300 |
---|---|---|
committer | Charlie Carley <snailrose@gmail.com> | 2007-01-21 07:45:44 +0300 |
commit | 557360224f5d65f4d39556e64f574508037e85ca (patch) | |
tree | 6c114586cce2027d6d9d2ef7d7036dda889918dd /source | |
parent | 3917b1af5f475b231ca73ae6ec2cceb52a20d573 (diff) |
Klockwork (http://www.klocwork.com) report; game engine fixes, related to 'Use Blender Materials'
/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;
Diffstat (limited to 'source')
5 files changed, 39 insertions, 28 deletions
diff --git a/source/gameengine/Ketsji/BL_Material.cpp b/source/gameengine/Ketsji/BL_Material.cpp index a8d80ef6224..7ed2da590a9 100644 --- a/source/gameengine/Ketsji/BL_Material.cpp +++ b/source/gameengine/Ketsji/BL_Material.cpp @@ -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; diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp index ce0809628ce..4e32d2cced9 100644 --- a/source/gameengine/Ketsji/BL_Shader.cpp +++ b/source/gameengine/Ketsji/BL_Shader.cpp @@ -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); diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index 426a3a1aab5..fa1c67f251c 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -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(); diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.cpp index b609c85dcbe..8014c4ebd2a 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.cpp @@ -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; } } } diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index e90411e05e8..53ec7a02e6f 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -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; } |