From e13c79d13e85fc0b6f4215f98fbcced48dc64ebc Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Tue, 12 Dec 2017 20:23:39 +0000 Subject: [PATCH] Fixed SVACE errors Change-Id: Ic2fbd3deaf69e4dfcc7ab512c70eae077b12bbc8 Signed-off-by: Adeel Kazmi Signed-off-by: Buildserver --- examples/image-view-url/image-view-url-example.cpp | 3 +- examples/ray-marching/ray-marching-example.cpp | 42 ++++++++++++++-------- examples/rendering-basic-pbr/ktx-loader.cpp | 24 ++++++++++--- .../rendering-basic-pbr-example.cpp | 30 ++++++++++------ 4 files changed, 69 insertions(+), 30 deletions(-) diff --git a/examples/image-view-url/image-view-url-example.cpp b/examples/image-view-url/image-view-url-example.cpp index ce98781..59ebda9 100644 --- a/examples/image-view-url/image-view-url-example.cpp +++ b/examples/image-view-url/image-view-url-example.cpp @@ -58,7 +58,8 @@ class ImageViewUrlApp : public ConnectionTracker { public: ImageViewUrlApp( Application& application ) - : mApplication( application ) + : mApplication( application ), + mDeltaPropertyIndex( Property::INVALID_INDEX ) { // Connect to the Application's Init signal mApplication.InitSignal().Connect( this, &ImageViewUrlApp::Create ); diff --git a/examples/ray-marching/ray-marching-example.cpp b/examples/ray-marching/ray-marching-example.cpp index 6bf0c20..d638217 100644 --- a/examples/ray-marching/ray-marching-example.cpp +++ b/examples/ray-marching/ray-marching-example.cpp @@ -41,20 +41,30 @@ bool LoadShaderCode( const char* path, const char* filename, std::vector& { std::string fullpath( path ); fullpath += filename; - FILE* f = fopen( fullpath.c_str(), "rb" ); - if( !f ) + FILE* file = fopen( fullpath.c_str(), "rb" ); + if( ! file ) { return false; } - fseek( f, 0, SEEK_END ); - size_t size = ftell( f ); - fseek( f, 0, SEEK_SET ); - output.resize( size + 1 ); - std::fill( output.begin(), output.end(), 0 ); - ssize_t result = fread( output.data(), size, 1, f ); - fclose( f ); - - return ( result >= 0 ); + + bool retValue = false; + if( ! fseek( file, 0, SEEK_END ) ) + { + long int size = ftell( file ); + + if( ( size != -1L ) && + ( ! fseek( file, 0, SEEK_SET ) ) ) + { + output.resize( size + 1 ); + std::fill( output.begin(), output.end(), 0 ); + ssize_t result = fread( output.data(), size, 1, file ); + + retValue = ( result >= 0 ); + } + } + + fclose( file ); + return retValue; } /** @@ -69,9 +79,13 @@ Shader LoadShaders( const std::string& shaderName ) std::string shaderFSH( shaderName ); shaderVSH += ".vsh"; shaderFSH += ".fsh"; - LoadShaderCode( DEMO_SHADER_DIR, shaderVSH.c_str(), bufV ); - LoadShaderCode( DEMO_SHADER_DIR, shaderFSH.c_str(), bufF ); - Shader shader = Shader::New( bufV.data(), bufF.data() ); + + Shader shader; + if( LoadShaderCode( DEMO_SHADER_DIR, shaderVSH.c_str(), bufV ) && + LoadShaderCode( DEMO_SHADER_DIR, shaderFSH.c_str(), bufF ) ) + { + shader = Shader::New( bufV.data(), bufF.data() ); + } return shader; } diff --git a/examples/rendering-basic-pbr/ktx-loader.cpp b/examples/rendering-basic-pbr/ktx-loader.cpp index b54704c..175d6c3 100644 --- a/examples/rendering-basic-pbr/ktx-loader.cpp +++ b/examples/rendering-basic-pbr/ktx-loader.cpp @@ -104,6 +104,7 @@ bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata ) int result = fread(&header,1,sizeof(KtxFileHeader),fp); if( 0 == result ) { + fclose( fp ); return false; } @@ -112,14 +113,27 @@ bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata ) // Skip the key-values: const long int imageSizeOffset = sizeof(KtxFileHeader) + header.bytesOfKeyValueData; - fseek(fp, imageSizeOffset, SEEK_END); + if( fseek(fp, imageSizeOffset, SEEK_END) ) + { + fclose( fp ); + return false; + } + lSize = ftell(fp); + if( lSize == -1L ) + { + fclose( fp ); + return false; + } + rewind(fp); - if(fseek(fp, imageSizeOffset, SEEK_SET)) + if( fseek(fp, imageSizeOffset, SEEK_SET) ) { + fclose( fp ); return false; } + cubedata.img.resize(header.numberOfFaces); for(unsigned int face=0; face < header.numberOfFaces; ++face) //array_element must be 0 or 1 @@ -133,13 +147,15 @@ bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata ) unsigned int imgSize[6]; unsigned char* imgPointer = buffer; result = fread(buffer,1,lSize,fp); + + fclose(fp); + if( 0 == result ) { + free( buffer ); return false; } - fclose(fp); - if( 0 == header.numberOfMipmapLevels ) { header.numberOfMipmapLevels = 1u; diff --git a/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp b/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp index 920a7b8..931f5fb 100644 --- a/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp +++ b/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp @@ -390,21 +390,29 @@ public: */ bool LoadShaderCode( const std::string& fullpath, std::vector& output ) { - FILE* f = fopen( fullpath.c_str(), "rb" ); - - if( NULL == f ) + FILE* file = fopen( fullpath.c_str(), "rb" ); + if( NULL == file ) { return false; } - fseek( f, 0, SEEK_END ); - size_t size = ftell( f ); - fseek( f, 0, SEEK_SET ); - output.resize( size + 1 ); - std::fill( output.begin(), output.end(), 0 ); - ssize_t result = fread( output.data(), size, 1, f ); - fclose( f ); - return ( result >= 0 ); + bool retValue = false; + if( ! fseek( file, 0, SEEK_END ) ) + { + long int size = ftell( file ); + + if( ( size != -1L ) && + ( ! fseek( file, 0, SEEK_SET ) ) ) + { + output.resize( size + 1 ); + std::fill( output.begin(), output.end(), 0 ); + ssize_t result = fread( output.data(), size, 1, file ); + + retValue = ( result >= 0 ); + } + } + fclose( file ); + return retValue; } /** -- 2.7.4