From 6402710910816e1b2669bcd482bc8c69b2eccc37 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 20 Jun 2011 19:33:47 +0000 Subject: [PATCH] Merged changes to svn/trunk that address cppcheck reported issues: [examples/osgphotoalbum/PhotoArchive.cpp:56]: (error) Memory leak: fileIndentifier [examples/osgphotoalbum/PhotoArchive.cpp:257]: (error) Deallocating a deallocated pointer: newData [examples/osgphotoalbum/PhotoArchive.cpp:318]: (error) Deallocating a deallocated pointer: newData [src/osg/ImageUtils.cpp:116]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/ImageUtils.cpp:307]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/ImageUtils.cpp:312]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/ImageUtils.cpp:367]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/ImageUtils.cpp:399]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/ImageUtils.cpp:400]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/ImageUtils.cpp:482]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/ImageUtils.cpp:483]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/ImageUtils.cpp:484]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/ImageUtils.cpp:519]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/ImageUtils.cpp:536]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/OcclusionQueryNode.cpp:71]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/OcclusionQueryNode.cpp:74]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/OcclusionQueryNode.cpp:77]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/OcclusionQueryNode.cpp:82]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/OcclusionQueryNode.cpp:102]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/OcclusionQueryNode.cpp:107]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/OcclusionQueryNode.cpp:599]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/OcclusionQueryNode.cpp:600]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/OcclusionQueryNode.cpp:601]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/OcclusionQueryNode.cpp:602]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/OcclusionQueryNode.cpp:603]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/OcclusionQueryNode.cpp:604]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/OcclusionQueryNode.cpp:605]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osg/OcclusionQueryNode.cpp:606]: (portability) Extra qualification 'osg::' unnecessary and considered an error by many compilers. [src/osgDB/ExternalFileWriter.cpp:134]: (portability) Extra qualification 'osgDB::' unnecessary and considered an error by many compilers. [src/osgDB/ExternalFileWriter.cpp:135]: (portability) Extra qualification 'osgDB::' unnecessary and considered an error by many compilers. [src/osgDB/ExternalFileWriter.cpp:136]: (portability) Extra qualification 'osgDB::' unnecessary and considered an error by many compilers. [src/osgDB/ExternalFileWriter.cpp:137]: (portability) Extra qualification 'osgDB::' unnecessary and considered an error by many compilers. [src/osgDB/ExternalFileWriter.cpp:139]: (portability) Extra qualification 'osgDB::' unnecessary and considered an error by many compilers. [src/osgDB/ExternalFileWriter.cpp:177]: (portability) Extra qualification 'osgDB::' unnecessary and considered an error by many compilers. [src/osgDB/ExternalFileWriter.cpp:178]: (portability) Extra qualification 'osgDB::' unnecessary and considered an error by many compilers. [src/osgDB/ExternalFileWriter.cpp:195]: (portability) Extra qualification 'osgDB::' unnecessary and considered an error by many compilers. [src/osgDB/ExternalFileWriter.cpp:198]: (portability) Extra qualification 'osgDB::' unnecessary and considered an error by many compilers. [src/osgDB/ExternalFileWriter.cpp:203]: (portability) Extra qualification 'osgDB::' unnecessary and considered an error by many compilers. [src/osgDB/ExternalFileWriter.cpp:205]: (portability) Extra qualification 'osgDB::' unnecessary and considered an error by many compilers. [src/osgDB/ExternalFileWriter.cpp:253]: (portability) Extra qualification 'osgDB::' unnecessary and considered an error by many compilers. [src/osgDB/InputStream.cpp:553]: (error) Memory leak: data [src/osgDB/OutputStream.cpp:393]: (error) Memory leak: data [src/osgPlugins/Inventor/ConvertToInventor.cpp:656]: (error) Mismatching allocation and deallocation: tmpArray [src/osgPlugins/Inventor/ReaderWriterIV.cpp:237]: (error) Common realloc mistake: 'buf' nulled but not freed upon failure [src/osgPlugins/OpenFlight/expGeometryRecords.cpp:167]: (portability) Extra qualification 'flt::' unnecessary and considered an error by many compilers. [src/osgPlugins/OpenFlight/expGeometryRecords.cpp:373]: (portability) Extra qualification 'flt::' unnecessary and considered an error by many compilers. [src/osgPlugins/cfg/CameraConfig.cpp:635]: (error) Unusual pointer arithmetic [src/osgPlugins/freetype/FreeTypeLibrary.cpp:122]: (error) Memory leak: buffer [src/osgPlugins/geo/ReaderWriterGEO.cpp:210]: (error) Possible null pointer dereference: gfd - otherwise it is redundant to check if gfd is null at line 211 [src/osgPlugins/geo/ReaderWriterGEO.cpp:227]: (error) Possible null pointer dereference: gfd - otherwise it is redundant to check if gfd is null at line 228 [src/osgPlugins/geo/ReaderWriterGEO.cpp:903]: (error) Possible null pointer dereference: gfd - otherwise it is redundant to check if gfd is null at line 904 [src/osgPlugins/geo/osgGeoNodes.h:180]: (error) Memory leak: geoHeaderGeo::intVars [src/osgPlugins/geo/osgGeoNodes.h:181]: (error) Memory leak: geoHeaderGeo::useVars [src/osgPlugins/geo/osgGeoNodes.h:182]: (error) Memory leak: geoHeaderGeo::extVars [src/osgPlugins/md2/ReaderWriterMD2.cpp:180]: (error) Memory leak: mapbase [src/osgPlugins/md2/ReaderWriterMD2.cpp:166]: (error) Resource leak: file_fd [src/osgPlugins/pic/ReaderWriterPIC.cpp:152]: (error) Mismatching allocation and deallocation: tmpbuf [src/osgPlugins/pic/ReaderWriterPIC.cpp:153]: (error) Mismatching allocation and deallocation: buffer [src/osgPlugins/ply/plyfile.cpp:843]: (error) Memory leak: plyfile [src/osgPlugins/pvr/ReaderWriterPVR.cpp:179]: (error) Memory leak: imageData [src/osgPlugins/shp/ESRIShapeParser.cpp:29]: (error) Resource leak: fd [src/osgPlugins/shp/XBaseParser.cpp:96]: (error) Resource leak: fd [src/osgPlugins/zip/unzip.cpp:3158]: (error) Possible null pointer dereference: s - otherwise it is redundant to check if s is null at line 3159 [src/osgPlugins/zip/unzip.cpp:4155]: (error) Dangerous usage of 'rd' (strncpy doesn't always 0-terminate it) [src/osgShadow/MinimalCullBoundsShadowMap.cpp:334]: (error) Possible null pointer dereference: rl - otherwise it is redundant to check if rl is null at line 331 [src/osgViewer/ScreenCaptureHandler.cpp:617]: (error) Possible null pointer dereference: camera - otherwise it is redundant to check if camera is null at line 611 [src/osgViewer/ScreenCaptureHandler.cpp:632]: (error) Possible null pointer dereference: camera - otherwise it is redundant to check if camera is null at line 626 [src/osgVolume/Locator.cpp:209]: (error) Dangerous iterator usage after erase()-method. [src/osgVolume/RayTracedTechnique.cpp:274]: (error) Possible null pointer dereference: imageLayer - otherwise it is redundant to check if imageLayer is null at line 259 [src/osgVolume/RayTracedTechnique.cpp:275]: (error) Possible null pointer dereference: imageLayer - otherwise it is redundant to check if imageLayer is null at line 259 [src/osgWrappers/serializers/osg/ShaderBinary.cpp:28]: (error) Mismatching allocation and deallocation: data --- examples/osgphotoalbum/PhotoArchive.cpp | 15 +- src/osg/ImageUtils.cpp | 22 +-- src/osg/OcclusionQueryNode.cpp | 172 +++++++----------- src/osgDB/ExternalFileWriter.cpp | 35 ++-- src/osgDB/InputStream.cpp | 4 +- src/osgDB/OutputStream.cpp | 4 +- src/osgPlugins/Inventor/ConvertToInventor.cpp | 2 +- src/osgPlugins/Inventor/ReaderWriterIV.cpp | 8 +- .../OpenFlight/expGeometryRecords.cpp | 4 +- src/osgPlugins/cfg/CameraConfig.cpp | 4 +- src/osgPlugins/freetype/FreeTypeLibrary.cpp | 1 + src/osgPlugins/geo/ReaderWriterGEO.cpp | 100 +++++++--- src/osgPlugins/geo/osgGeoNodes.h | 26 +-- src/osgPlugins/md2/ReaderWriterMD2.cpp | 19 +- src/osgPlugins/pic/ReaderWriterPIC.cpp | 4 +- src/osgPlugins/ply/plyfile.cpp | 27 ++- src/osgPlugins/pvr/ReaderWriterPVR.cpp | 13 +- src/osgPlugins/shp/ESRIShapeParser.cpp | 1 + src/osgPlugins/shp/XBaseParser.cpp | 3 +- src/osgPlugins/zip/unzip.cpp | 24 ++- src/osgShadow/MinimalCullBoundsShadowMap.cpp | 2 +- src/osgViewer/ScreenCaptureHandler.cpp | 6 +- src/osgVolume/Locator.cpp | 1 + src/osgVolume/RayTracedTechnique.cpp | 10 - .../serializers/osg/ShaderBinary.cpp | 2 +- 25 files changed, 277 insertions(+), 232 deletions(-) diff --git a/examples/osgphotoalbum/PhotoArchive.cpp b/examples/osgphotoalbum/PhotoArchive.cpp index 59eac5d3e..1cf750ee7 100644 --- a/examples/osgphotoalbum/PhotoArchive.cpp +++ b/examples/osgphotoalbum/PhotoArchive.cpp @@ -41,7 +41,12 @@ bool PhotoArchive::readPhotoIndex(const std::string& filename) char* fileIndentifier = new char [FILE_IDENTIFER.size()]; in.read(fileIndentifier,FILE_IDENTIFER.size()); - if (FILE_IDENTIFER!=fileIndentifier) return false; + if (FILE_IDENTIFER!=fileIndentifier) + { + delete [] fileIndentifier; + return false; + } + delete [] fileIndentifier; unsigned int numPhotos; in.read((char*)&numPhotos,sizeof(numPhotos)); @@ -231,9 +236,9 @@ void PhotoArchive::buildArchive(const std::string& filename, const FileNameList& if (status!=0) { - delete [] newData; - + delete [] newData; osg::notify(osg::WARN) << "Error scaleImage() did not succeed : errorString = "<setMode( GL_LIGHTING, osg::StateAttribute::OFF | - osg::StateAttribute::PROTECTED); - state->setTextureMode( 0, GL_TEXTURE_2D, osg::StateAttribute::OFF | - osg::StateAttribute::PROTECTED); - state->setMode( GL_CULL_FACE, osg::StateAttribute::ON | - osg::StateAttribute::PROTECTED); + state->setMode( GL_LIGHTING, StateAttribute::OFF | StateAttribute::PROTECTED); + state->setTextureMode( 0, GL_TEXTURE_2D, StateAttribute::OFF | StateAttribute::PROTECTED); + state->setMode( GL_CULL_FACE, StateAttribute::ON | StateAttribute::PROTECTED); - osg::ColorMask* cm = new osg::ColorMask( false, false, false, false ); - state->setAttributeAndModes( cm, osg::StateAttribute::ON | - osg::StateAttribute::PROTECTED); - osg::Depth* d = new osg::Depth( osg::Depth::LEQUAL, 0.f, 1.f, false ); - state->setAttributeAndModes( d, osg::StateAttribute::ON | - osg::StateAttribute::PROTECTED); - osg::PolygonMode* pm = new osg::PolygonMode( - osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::FILL ); - state->setAttributeAndModes( pm, osg::StateAttribute::ON | - osg::StateAttribute::PROTECTED); + ColorMask* cm = new ColorMask( false, false, false, false ); + state->setAttributeAndModes( cm, StateAttribute::ON | StateAttribute::PROTECTED); - osg::PolygonOffset* po = new osg::PolygonOffset( -1., -1. ); - state->setAttributeAndModes( po, osg::StateAttribute::ON | - osg::StateAttribute::PROTECTED); + Depth* d = new Depth( Depth::LEQUAL, 0.f, 1.f, false ); + state->setAttributeAndModes( d, StateAttribute::ON | StateAttribute::PROTECTED); + + PolygonMode* pm = new PolygonMode( PolygonMode::FRONT_AND_BACK, PolygonMode::FILL ); + state->setAttributeAndModes( pm, StateAttribute::ON | StateAttribute::PROTECTED); + + PolygonOffset* po = new PolygonOffset( -1., -1. ); + state->setAttributeAndModes( po, StateAttribute::ON | StateAttribute::PROTECTED); return state; } // Create and return a StateSet for rendering a debug representation of query geometry. -osg::StateSet* -initOQDebugState() +StateSet* initOQDebugState() { osg::StateSet* debugState = new osg::StateSet; - debugState->setMode( GL_LIGHTING, osg::StateAttribute::OFF | - osg::StateAttribute::PROTECTED); - debugState->setTextureMode( 0, GL_TEXTURE_2D, osg::StateAttribute::OFF | - osg::StateAttribute::PROTECTED); - debugState->setMode( GL_CULL_FACE, osg::StateAttribute::ON | - osg::StateAttribute::PROTECTED); + debugState->setMode( GL_LIGHTING, StateAttribute::OFF | StateAttribute::PROTECTED); + debugState->setTextureMode( 0, GL_TEXTURE_2D, StateAttribute::OFF | StateAttribute::PROTECTED); + debugState->setMode( GL_CULL_FACE, StateAttribute::ON | StateAttribute::PROTECTED); - osg::PolygonMode* pm = new osg::PolygonMode( - osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE ); - debugState->setAttributeAndModes( pm, osg::StateAttribute::ON | - osg::StateAttribute::PROTECTED); + PolygonMode* pm = new PolygonMode( PolygonMode::FRONT_AND_BACK, PolygonMode::LINE ); + debugState->setAttributeAndModes( pm, StateAttribute::ON | StateAttribute::PROTECTED); - osg::PolygonOffset* po = new osg::PolygonOffset( -1., -1. ); - debugState->setAttributeAndModes( po, osg::StateAttribute::ON | - osg::StateAttribute::PROTECTED); + PolygonOffset* po = new PolygonOffset( -1., -1. ); + debugState->setAttributeAndModes( po, StateAttribute::ON | StateAttribute::PROTECTED); return debugState; } @@ -484,7 +470,7 @@ OcclusionQueryNode::~OcclusionQueryNode() { } -OcclusionQueryNode::OcclusionQueryNode( const OcclusionQueryNode& oqn, const osg::CopyOp& copyop ) +OcclusionQueryNode::OcclusionQueryNode( const OcclusionQueryNode& oqn, const CopyOp& copyop ) : Group( oqn, copyop ), _passed( false ) { @@ -498,8 +484,7 @@ OcclusionQueryNode::OcclusionQueryNode( const OcclusionQueryNode& oqn, const osg } -bool -OcclusionQueryNode::getPassed( const osg::Camera* camera, osg::NodeVisitor& nv ) +bool OcclusionQueryNode::getPassed( const Camera* camera, NodeVisitor& nv ) { if ( !_enabled ) // Queries are not enabled. The caller should be osgUtil::CullVisitor, @@ -551,8 +536,7 @@ OcclusionQueryNode::getPassed( const osg::Camera* camera, osg::NodeVisitor& nv ) return _passed; } -void -OcclusionQueryNode::traverseQuery( const osg::Camera* camera, osg::NodeVisitor& nv ) +void OcclusionQueryNode::traverseQuery( const Camera* camera, NodeVisitor& nv ) { bool issueQuery; { @@ -568,16 +552,14 @@ OcclusionQueryNode::traverseQuery( const osg::Camera* camera, osg::NodeVisitor& _queryGeode->accept( nv ); } -void -OcclusionQueryNode::traverseDebug( osg::NodeVisitor& nv ) +void OcclusionQueryNode::traverseDebug( NodeVisitor& nv ) { if (_debugBB) // If requested, display the debug geometry _debugGeode->accept( nv ); } -osg::BoundingSphere -OcclusionQueryNode::computeBound() const +BoundingSphere OcclusionQueryNode::computeBound() const { { // Need to make this routine thread-safe. Typically called by the update @@ -590,22 +572,22 @@ OcclusionQueryNode::computeBound() const osg::OcclusionQueryNode* nonConstThis = const_cast( this ); - osg::ComputeBoundsVisitor cbv; + ComputeBoundsVisitor cbv; nonConstThis->accept( cbv ); - osg::BoundingBox bb = cbv.getBoundingBox(); + BoundingBox bb = cbv.getBoundingBox(); - osg::ref_ptr v = new osg::Vec3Array; + osg::ref_ptr v = new Vec3Array; v->resize( 8 ); - (*v)[0] = osg::Vec3( bb._min.x(), bb._min.y(), bb._min.z() ); - (*v)[1] = osg::Vec3( bb._max.x(), bb._min.y(), bb._min.z() ); - (*v)[2] = osg::Vec3( bb._max.x(), bb._min.y(), bb._max.z() ); - (*v)[3] = osg::Vec3( bb._min.x(), bb._min.y(), bb._max.z() ); - (*v)[4] = osg::Vec3( bb._max.x(), bb._max.y(), bb._min.z() ); - (*v)[5] = osg::Vec3( bb._min.x(), bb._max.y(), bb._min.z() ); - (*v)[6] = osg::Vec3( bb._min.x(), bb._max.y(), bb._max.z() ); - (*v)[7] = osg::Vec3( bb._max.x(), bb._max.y(), bb._max.z() ); + (*v)[0] = Vec3( bb._min.x(), bb._min.y(), bb._min.z() ); + (*v)[1] = Vec3( bb._max.x(), bb._min.y(), bb._min.z() ); + (*v)[2] = Vec3( bb._max.x(), bb._min.y(), bb._max.z() ); + (*v)[3] = Vec3( bb._min.x(), bb._min.y(), bb._max.z() ); + (*v)[4] = Vec3( bb._max.x(), bb._max.y(), bb._min.z() ); + (*v)[5] = Vec3( bb._min.x(), bb._max.y(), bb._min.z() ); + (*v)[6] = Vec3( bb._min.x(), bb._max.y(), bb._max.z() ); + (*v)[7] = Vec3( bb._max.x(), bb._max.y(), bb._max.z() ); - osg::Geometry* geom = static_cast< osg::Geometry* >( nonConstThis->_queryGeode->getDrawable( 0 ) ); + Geometry* geom = static_cast< Geometry* >( nonConstThis->_queryGeode->getDrawable( 0 ) ); geom->setVertexArray( v.get() ); geom = static_cast< osg::Geometry* >( nonConstThis->_debugGeode->getDrawable( 0 ) ); @@ -617,28 +599,23 @@ OcclusionQueryNode::computeBound() const // Should only be called outside of cull/draw. No thread issues. -void -OcclusionQueryNode::setQueriesEnabled( bool enable ) +void OcclusionQueryNode::setQueriesEnabled( bool enable ) { _enabled = enable; } // Should only be called outside of cull/draw. No thread issues. -void -OcclusionQueryNode::setDebugDisplay( bool debug ) +void OcclusionQueryNode::setDebugDisplay( bool debug ) { _debugBB = debug; } -bool -OcclusionQueryNode::getDebugDisplay() const + +bool OcclusionQueryNode::getDebugDisplay() const { return _debugBB; } - - -void -OcclusionQueryNode::setQueryStateSet( osg::StateSet* ss ) +void OcclusionQueryNode::setQueryStateSet( StateSet* ss ) { if (!_queryGeode) { @@ -648,8 +625,8 @@ OcclusionQueryNode::setQueryStateSet( osg::StateSet* ss ) _queryGeode->setStateSet( ss ); } -osg::StateSet* -OcclusionQueryNode::getQueryStateSet() + +StateSet* OcclusionQueryNode::getQueryStateSet() { if (!_queryGeode) { @@ -659,8 +636,7 @@ OcclusionQueryNode::getQueryStateSet() return _queryGeode->getStateSet(); } -const osg::StateSet* -OcclusionQueryNode::getQueryStateSet() const +const StateSet* OcclusionQueryNode::getQueryStateSet() const { if (!_queryGeode) { @@ -670,8 +646,7 @@ OcclusionQueryNode::getQueryStateSet() const return _queryGeode->getStateSet(); } -void -OcclusionQueryNode::setDebugStateSet( osg::StateSet* ss ) +void OcclusionQueryNode::setDebugStateSet( StateSet* ss ) { if (!_debugGeode) { @@ -681,8 +656,7 @@ OcclusionQueryNode::setDebugStateSet( osg::StateSet* ss ) _debugGeode->setStateSet( ss ); } -osg::StateSet* -OcclusionQueryNode::getDebugStateSet() +StateSet* OcclusionQueryNode::getDebugStateSet() { if (!_debugGeode.valid()) { @@ -691,8 +665,7 @@ OcclusionQueryNode::getDebugStateSet() } return _debugGeode->getStateSet(); } -const osg::StateSet* -OcclusionQueryNode::getDebugStateSet() const +const StateSet* OcclusionQueryNode::getDebugStateSet() const { if (!_debugGeode.valid()) { @@ -702,15 +675,13 @@ OcclusionQueryNode::getDebugStateSet() const return _debugGeode->getStateSet(); } -bool -OcclusionQueryNode::getPassed() const +bool OcclusionQueryNode::getPassed() const { return _passed; } -void -OcclusionQueryNode::createSupportNodes() +void OcclusionQueryNode::createSupportNodes() { GLushort indices[] = { 0, 1, 2, 3, 4, 5, 6, 7, 0, 3, 6, 5, 2, 1, 4, 7, @@ -718,14 +689,13 @@ OcclusionQueryNode::createSupportNodes() { // Add the test geometry Geode - _queryGeode = new osg::Geode; + _queryGeode = new Geode; _queryGeode->setName( "OQTest" ); - _queryGeode->setDataVariance( osg::Object::DYNAMIC ); + _queryGeode->setDataVariance( Object::DYNAMIC ); - osg::ref_ptr< QueryGeometry > geom = new QueryGeometry( getName() ); - geom->setDataVariance( osg::Object::DYNAMIC ); - geom->addPrimitiveSet( new osg::DrawElementsUShort( - osg::PrimitiveSet::QUADS, 24, indices ) ); + ref_ptr< QueryGeometry > geom = new QueryGeometry( getName() ); + geom->setDataVariance( Object::DYNAMIC ); + geom->addPrimitiveSet( new DrawElementsUShort( PrimitiveSet::QUADS, 24, indices ) ); _queryGeode->addDrawable( geom.get() ); } @@ -733,20 +703,19 @@ OcclusionQueryNode::createSupportNodes() { // Add a Geode that is a visual representation of the // test geometry for debugging purposes - _debugGeode = new osg::Geode; + _debugGeode = new Geode; _debugGeode->setName( "Debug" ); - _debugGeode->setDataVariance( osg::Object::DYNAMIC ); + _debugGeode->setDataVariance( Object::DYNAMIC ); - osg::ref_ptr geom = new osg::Geometry; - geom->setDataVariance( osg::Object::DYNAMIC ); + ref_ptr geom = new Geometry; + geom->setDataVariance( Object::DYNAMIC ); - osg::ref_ptr ca = new osg::Vec4Array; - ca->push_back( osg::Vec4( 1.f, 1.f, 1.f, 1.f ) ); + ref_ptr ca = new Vec4Array; + ca->push_back( Vec4( 1.f, 1.f, 1.f, 1.f ) ); geom->setColorArray( ca.get() ); - geom->setColorBinding( osg::Geometry::BIND_OVERALL ); + geom->setColorBinding( Geometry::BIND_OVERALL ); - geom->addPrimitiveSet( new osg::DrawElementsUShort( - osg::PrimitiveSet::QUADS, 24, indices ) ); + geom->addPrimitiveSet( new DrawElementsUShort( PrimitiveSet::QUADS, 24, indices ) ); _debugGeode->addDrawable( geom.get() ); } @@ -759,8 +728,7 @@ OcclusionQueryNode::createSupportNodes() } -void -OcclusionQueryNode::releaseGLObjects( osg::State* state ) const +void OcclusionQueryNode::releaseGLObjects( State* state ) const { if(_queryGeode->getDrawable( 0 ) != NULL) { @@ -771,15 +739,13 @@ OcclusionQueryNode::releaseGLObjects( osg::State* state ) const } } -void -OcclusionQueryNode::flushDeletedQueryObjects( unsigned int contextID, double currentTime, double& availableTime ) +void OcclusionQueryNode::flushDeletedQueryObjects( unsigned int contextID, double currentTime, double& availableTime ) { // Query object discard and deletion is handled by QueryGeometry support class. QueryGeometry::flushDeletedQueryObjects( contextID, currentTime, availableTime ); } -void -OcclusionQueryNode::discardDeletedQueryObjects( unsigned int contextID ) +void OcclusionQueryNode::discardDeletedQueryObjects( unsigned int contextID ) { // Query object discard and deletion is handled by QueryGeometry support class. QueryGeometry::discardDeletedQueryObjects( contextID ); diff --git a/src/osgDB/ExternalFileWriter.cpp b/src/osgDB/ExternalFileWriter.cpp index c269f29ca..bc3eed5bf 100644 --- a/src/osgDB/ExternalFileWriter.cpp +++ b/src/osgDB/ExternalFileWriter.cpp @@ -32,9 +32,8 @@ static unsigned int countNbDirsUp(const std::string & path) // Algorithm: // - For each path component, count +1 for "..", 0 for ".", and -1 for anything else // - Ignore everything after the last ".." of the path. - if (osgDB::isAbsolutePath(path)) return 0; + if (isAbsolutePath(path)) return 0; int result(0), tempResult(0); - //for(osgDB::PathIterator it(path); it.valid(); ++it) std::vector pathElems; getPathElements(path, pathElems); for(std::vector::const_iterator it(pathElems.begin()), itEnd(pathElems.end()); it!=itEnd; ++it) @@ -131,12 +130,12 @@ inline const std::string & getFileName(const osg::Object & obj, WriteType type) inline bool doWrite(const osg::Object & obj, WriteType type, const std::string& fileName, const Options * options) { switch(type) { - case WRITE_TYPE_IMAGE: return osgDB::writeImageFile (static_cast(obj), fileName, options); - case WRITE_TYPE_HEIGHT_FIELD: return osgDB::writeHeightFieldFile(static_cast(obj), fileName, options); - case WRITE_TYPE_NODE: return osgDB::writeNodeFile (static_cast(obj), fileName, options); - case WRITE_TYPE_SHADER: return osgDB::writeShaderFile (static_cast(obj), fileName, options); - default: // WRITE_TYPE_OBJECT - return osgDB::writeObjectFile(obj, fileName, options); + case WRITE_TYPE_IMAGE: return writeImageFile (static_cast(obj), fileName, options); + case WRITE_TYPE_HEIGHT_FIELD: return writeHeightFieldFile(static_cast(obj), fileName, options); + case WRITE_TYPE_NODE: return writeNodeFile (static_cast(obj), fileName, options); + case WRITE_TYPE_SHADER: return writeShaderFile (static_cast(obj), fileName, options); + // WRITE_TYPE_OBJECT + default: return writeObjectFile(obj, fileName, options); } } @@ -154,7 +153,7 @@ ExternalFileWriter::ExternalFileWriter(const std::string & destDirectory) {} -bool ExternalFileWriter::write(const osg::Object & obj, const osgDB::Options * options, std::string * out_absolutePath, std::string * out_relativePath) +bool ExternalFileWriter::write(const osg::Object & obj, const Options * options, std::string * out_absolutePath, std::string * out_relativePath) { ObjectsSet::iterator it( _objects.find(&obj) ); if (it != _objects.end()) @@ -173,9 +172,9 @@ bool ExternalFileWriter::write(const osg::Object & obj, const osgDB::Options * o std::string absoluteSourcePath; if (_keepRelativePaths && !originalFileName.empty()) // if keepRelativePaths is false, absoluteSourcePath is not used, then we can skip this part { - if (osgDB::isAbsolutePath(originalFileName)) absoluteSourcePath = originalFileName; - else absoluteSourcePath = osgDB::concatPaths(_srcDirectory, originalFileName); - absoluteSourcePath = osgDB::getRealPath(osgDB::convertFileNameToNativeStyle(absoluteSourcePath)); // getRealPath() here is only used to canonize the path, not to add current directory in front of relative paths, hence the "concatPaths(_srcDirectory, ...)" just above + if (isAbsolutePath(originalFileName)) absoluteSourcePath = originalFileName; + else absoluteSourcePath = concatPaths(_srcDirectory, originalFileName); + absoluteSourcePath = getRealPath(convertFileNameToNativeStyle(absoluteSourcePath)); // getRealPath() here is only used to canonize the path, not to add current directory in front of relative paths, hence the "concatPaths(_srcDirectory, ...)" just above } // Compute destination paths from the source path @@ -192,23 +191,23 @@ bool ExternalFileWriter::write(const osg::Object & obj, const osgDB::Options * o if (_keepRelativePaths) { // We'll try to keep images relative path. - relativeDestinationPath = osgDB::getPathRelative(_srcDirectory, absoluteSourcePath); + relativeDestinationPath = getPathRelative(_srcDirectory, absoluteSourcePath); unsigned int nbDirsUp = countNbDirsUp(relativeDestinationPath); // TODO if nbDirsUp>nb dirs in _destDirectory, then issue a warning, and use simple file name - if (nbDirsUp > _allowUpDirs) relativeDestinationPath = osgDB::getSimpleFileName(absoluteSourcePath); + if (nbDirsUp > _allowUpDirs) relativeDestinationPath = getSimpleFileName(absoluteSourcePath); } else { // We keep only the simple file name. - relativeDestinationPath = osgDB::getSimpleFileName(absoluteSourcePath); + relativeDestinationPath = getSimpleFileName(absoluteSourcePath); } - absoluteDestinationPath = osgDB::getRealPath(osgDB::convertFileNameToNativeStyle( osgDB::concatPaths(_destDirectory, relativeDestinationPath) )); + absoluteDestinationPath = getRealPath(convertFileNameToNativeStyle( concatPaths(_destDirectory, relativeDestinationPath) )); // TODO Check for absolute paths collisions between multiple objects } // Write object bool written(false); - if (!osgDB::makeDirectoryForFile(absoluteDestinationPath)) + if (!makeDirectoryForFile(absoluteDestinationPath)) { OSG_NOTICE << "Can't create directory for file '" << absoluteDestinationPath << "'. May fail creating the image file." << std::endl; } @@ -250,7 +249,7 @@ void ExternalFileWriter::generateObjectName(std::string & out_relativePath, std: std::ostringstream oss; oss << FILE_PREFIX[type] << number << FILE_EXTENSION[type]; out_relativePath = oss.str(); - out_absolutePath = osgDB::concatPaths(_destDirectory, out_relativePath); + out_absolutePath = concatPaths(_destDirectory, out_relativePath); if (!absoluteObjectPathExists(out_absolutePath)) { diff --git a/src/osgDB/InputStream.cpp b/src/osgDB/InputStream.cpp index ad31a94cf..b24917b0e 100644 --- a/src/osgDB/InputStream.cpp +++ b/src/osgDB/InputStream.cpp @@ -549,8 +549,10 @@ osg::Image* InputStream::readImage(bool readFromExternal) { char* data = new char[size]; if ( !data ) + { throwException( "InputStream::readImage(): Out of memory." ); - if ( getException() ) return NULL; + if ( getException() ) return NULL; + } readCharArray( data, size ); std::string ext = osgDB::getFileExtension( name ); diff --git a/src/osgDB/OutputStream.cpp b/src/osgDB/OutputStream.cpp index 1d4eeabbb..fee2ede6e 100644 --- a/src/osgDB/OutputStream.cpp +++ b/src/osgDB/OutputStream.cpp @@ -389,8 +389,10 @@ void OutputStream::writeImage( const osg::Image* img ) { char* data = new char[size]; if ( !data ) + { throwException( "OutputStream::writeImage(): Out of memory." ); - if ( getException() ) return; + if ( getException() ) return; + } infile.seekg( 0, std::ios::beg ); infile.read( data, size ); diff --git a/src/osgPlugins/Inventor/ConvertToInventor.cpp b/src/osgPlugins/Inventor/ConvertToInventor.cpp index f00205926..9fe774773 100644 --- a/src/osgPlugins/Inventor/ConvertToInventor.cpp +++ b/src/osgPlugins/Inventor/ConvertToInventor.cpp @@ -653,7 +653,7 @@ static void postProcessField(const SbIntList &runLengths, osg::PrimitiveSet::Mod field->finishEditing(); // free resources - delete tmpArray; + delete [] tmpArray; } diff --git a/src/osgPlugins/Inventor/ReaderWriterIV.cpp b/src/osgPlugins/Inventor/ReaderWriterIV.cpp index d21667e00..a2cf4459d 100644 --- a/src/osgPlugins/Inventor/ReaderWriterIV.cpp +++ b/src/osgPlugins/Inventor/ReaderWriterIV.cpp @@ -234,7 +234,13 @@ ReaderWriterIV::readNode(std::istream& fin, dataSize += fin.gcount(); if (bufSize == dataSize) { bufSize *= 2; - buf = (char*)realloc(buf, bufSize); + char* new_buf = (char*)realloc(buf, bufSize); + if (!new_buf) + { + free(buf); + return osgDB::ReaderWriter::ReadResult::INSUFFICIENT_MEMORY_TO_LOAD; + } + buf = new_buf; } } input.setBuffer(buf, dataSize); diff --git a/src/osgPlugins/OpenFlight/expGeometryRecords.cpp b/src/osgPlugins/OpenFlight/expGeometryRecords.cpp index 9eb500e31..3bfb1ef4e 100644 --- a/src/osgPlugins/OpenFlight/expGeometryRecords.cpp +++ b/src/osgPlugins/OpenFlight/expGeometryRecords.cpp @@ -164,7 +164,7 @@ FltExportVisitor::writeFace( const osg::Geode& geode, const osg::Geometry& geom, if (c && (c->size() > 0)) { packedColorRaw = (*c)[0]; - transparency = flt::uint16((1. - packedColorRaw[3]) * (double)0xffff); + transparency = uint16((1. - packedColorRaw[3]) * (double)0xffff); } if ( isLit( geom ) ) @@ -370,7 +370,7 @@ FltExportVisitor::writeMesh( const osg::Geode& geode, const osg::Geometry& geom if (c && (c->size() > 0)) { packedColorRaw = (*c)[0]; - transparency = flt::uint16((1. - packedColorRaw[3]) * (double)0xffff); + transparency = uint16((1. - packedColorRaw[3]) * (double)0xffff); } if (isLit( geom )) diff --git a/src/osgPlugins/cfg/CameraConfig.cpp b/src/osgPlugins/cfg/CameraConfig.cpp index cd193993e..4c233b22d 100644 --- a/src/osgPlugins/cfg/CameraConfig.cpp +++ b/src/osgPlugins/cfg/CameraConfig.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "CameraConfig.h" @@ -632,7 +633,8 @@ bool CameraConfig::defaultConfig() for( unsigned int i = 0; i < numScreens; i++ ) { - std::string name = "Screen" + i; + std::stringstream sstr; sstr<<"Screen"< >::iterator,bool> res = _camera_map.insert(std::pair >(name, new Camera)); diff --git a/src/osgPlugins/freetype/FreeTypeLibrary.cpp b/src/osgPlugins/freetype/FreeTypeLibrary.cpp index 2969093b6..be002bd63 100644 --- a/src/osgPlugins/freetype/FreeTypeLibrary.cpp +++ b/src/osgPlugins/freetype/FreeTypeLibrary.cpp @@ -119,6 +119,7 @@ FT_Byte* FreeTypeLibrary::getFace(std::istream& fontstream, unsigned int index, if (!fontstream || (static_cast(fontstream.gcount()) != length)) { OSG_WARN<<" .... the font file could not be read from its stream"<clear(); + delete color_palette; + } +} + + const geoValue *geoHeaderGeo::getGeoVar(const unsigned fid) const { const geoValue *st=intVars->getGeoVar(fid); if (!st) { @@ -207,37 +233,50 @@ public: int shademodel=gfshade ? gfshade->getInt() : -1; if (shademodel!=GEO_POLY_SHADEMODEL_LIT && shademodel!=GEO_POLY_SHADEMODEL_FLAT) { const geoField *gfd=gr->getField(GEO_DB_VRTX_NORMAL); - if (gfd->getType()==DB_UINT) { - if (gfd) { + if (gfd) + { + if (gfd->getType()==DB_UINT) + { unsigned int idx=gfd->getUInt(); normindices->push_back(idx); norms->push_back((*npool)[idx]); - } else { + } + else if (gfd->getType()==DB_VEC3F) + { + float *p=gfd->getVec3Arr(); + osg::Vec3 nrm; + nrm.set(p[0],p[1],p[2]); + norms->push_back(nrm); + } + else + { OSG_WARN << "No valid vertex index" << std::endl; } - } else if (gfd->getType()==DB_VEC3F) { - float *p=gfd->getVec3Arr(); - osg::Vec3 nrm; - nrm.set(p[0],p[1],p[2]); - norms->push_back(nrm); } } - const geoField *gfd=gr->getField(GEO_DB_VRTX_COORD); osg::Vec3 pos; - if (gfd->getType()==DB_INT) { - if (gfd) { - int idx=gfd->getInt(); + const geoField *gfd=gr->getField(GEO_DB_VRTX_COORD); + if (gfd) + { + if (gfd->getType()==DB_INT) + { + int idx=gfd->getInt(); pos=(*cpool)[idx]; coords->push_back((*cpool)[idx]); //osg::Vec3(cpool[3*idx],cpool[3*idx+1],cpool[3*idx+2])); coordindices->push_back(coords->size()); - } else { + } + else if (gfd->getType()==DB_VEC3F) + { + float *p=gfd->getVec3Arr(); + pos.set(p[0],p[1],p[2]); + coords->push_back(pos); //osg::Vec3(cpool[3*idx],cpool[3*idx+1],cpool[3*idx+2])); + } + else + { OSG_WARN << "No valid vertex index" << std::endl; } - } else if (gfd->getType()==DB_VEC3F) { - float *p=gfd->getVec3Arr(); - pos.set(p[0],p[1],p[2]); - coords->push_back(pos); //osg::Vec3(cpool[3*idx],cpool[3*idx+1],cpool[3*idx+2])); } + std::vector< georecord *>bhv=gr->getBehaviour(); // behaviours for vertices, eg tranlate, colour! if (!bhv.empty()) { int ncoord=coords->size(); @@ -898,19 +937,24 @@ class ReaderGEO (*itr)->getType()==DB_DSK_FAT_VERTEX || (*itr)->getType()==DB_DSK_SLIM_VERTEX) { // light point vertices - const geoField *gfd=(*itr)->getField(GEO_DB_VRTX_COORD); osg::Vec3 pos; - if (gfd->getType()==DB_INT) { - if (gfd) { - int idx=gfd->getInt(); - pos=coord_pool[idx]; - } else { + const geoField *gfd=(*itr)->getField(GEO_DB_VRTX_COORD); + if (gfd) { + if (gfd->getType()==DB_INT) + { + int idx=gfd->getInt(); + pos=coord_pool[idx]; + } + else if (gfd->getType()==DB_VEC3F) + { + float *p=gfd->getVec3Arr(); + pos.set(p[0],p[1],p[2]); + } + else { OSG_WARN << "No valid vertex index" << std::endl; } - } else if (gfd->getType()==DB_VEC3F) { - float *p=gfd->getVec3Arr(); - pos.set(p[0],p[1],p[2]); } + gfd=(*itr)->getField(GEO_DB_VRTX_PACKED_COLOR); if (gfd) { unsigned char *cls=gfd->getUCh4Arr(); diff --git a/src/osgPlugins/geo/osgGeoNodes.h b/src/osgPlugins/geo/osgGeoNodes.h index 0e0836383..fcb0e08e0 100644 --- a/src/osgPlugins/geo/osgGeoNodes.h +++ b/src/osgPlugins/geo/osgGeoNodes.h @@ -131,12 +131,8 @@ class geoHeaderGeo: public geoHeader { // including animation variables. public: geoHeaderGeo(); - ~geoHeaderGeo() { color_palette->clear(); } - geoHeaderGeo(const geoHeaderGeo &geo,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : - geoHeader(geo,copyop){ - intVars=new internalVars(*geo.intVars); useVars=new userVars(*geo.useVars); - extVars=new userVars(*geo.extVars); - } + geoHeaderGeo(const geoHeaderGeo &geo,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + void addInternalVars(const georecord &gr) { intVars->addInternalVars(gr);} internalVars *getInternalVars(void) const { return intVars;} const std::string getVarname(const unsigned fid) const { @@ -174,14 +170,18 @@ public: } void addColour(unsigned char *cpal) {(*color_palette).push_back(cpal);} inline colourPalette *getColorPalette() const { return color_palette;} + +protected: + virtual ~geoHeaderGeo(); + private: - osg::Timer_t _lastFrameTick,_initialTick; - osg::Timer _timer; - internalVars *intVars; - userVars *useVars; - userVars *extVars; - void moveit(const double t); - colourPalette *color_palette; // the colour palette - used in colour animations + void moveit(const double t); + osg::Timer_t _lastFrameTick,_initialTick; + osg::Timer _timer; + internalVars *intVars; + userVars *useVars; + userVars *extVars; + colourPalette *color_palette; // the colour palette - used in colour animations }; #endif diff --git a/src/osgPlugins/md2/ReaderWriterMD2.cpp b/src/osgPlugins/md2/ReaderWriterMD2.cpp index cc75bfcd7..cd326bff8 100644 --- a/src/osgPlugins/md2/ReaderWriterMD2.cpp +++ b/src/osgPlugins/md2/ReaderWriterMD2.cpp @@ -153,7 +153,6 @@ load_md2 (const char *filename, const osgDB::ReaderWriter::Options* options) { struct stat st; void *mapbase; -// void *p; int file_fd; osg::Node* result = NULL; @@ -163,23 +162,23 @@ load_md2 (const char *filename, const osgDB::ReaderWriter::Options* options) file_fd = open (filename, O_RDONLY); if (file_fd <= 0) { - return NULL; - } - -#if 0 - mapbase = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, file_fd, 0); - if (mapbase == NULL) { close (file_fd); return NULL; } -#else + mapbase = malloc (st.st_size); - if (read(file_fd, mapbase, st.st_size)==0) + if (!mapbase) { close (file_fd); return NULL; } -#endif + + if (read(file_fd, mapbase, st.st_size)==0) + { + close (file_fd); + if (mapbase) free(mapbase); + return NULL; + } if (g_md2NormalsArray == NULL) { g_md2NormalsArray = new osg::Vec3Array; diff --git a/src/osgPlugins/pic/ReaderWriterPIC.cpp b/src/osgPlugins/pic/ReaderWriterPIC.cpp index 69f5c5f87..94b5c5804 100644 --- a/src/osgPlugins/pic/ReaderWriterPIC.cpp +++ b/src/osgPlugins/pic/ReaderWriterPIC.cpp @@ -149,8 +149,8 @@ int *numComponents_ret) if (tmpbuf == NULL || buffer == NULL) { picerror = ERROR_MEMORY; - if (tmpbuf) free(tmpbuf); - if (buffer) free(buffer); + if (tmpbuf) delete [] tmpbuf; + if (buffer) delete [] buffer; fclose(fp); return NULL; } diff --git a/src/osgPlugins/ply/plyfile.cpp b/src/osgPlugins/ply/plyfile.cpp index 2b66a6090..7c85468a1 100644 --- a/src/osgPlugins/ply/plyfile.cpp +++ b/src/osgPlugins/ply/plyfile.cpp @@ -828,6 +828,8 @@ PlyFile *ply_read(FILE *fp, int *nelems, char ***elem_names) /* create record for this object */ plyfile = (PlyFile *) myalloc (sizeof (PlyFile)); + if (!plyfile) return (NULL); + plyfile->nelems = 0; plyfile->comments = NULL; plyfile->num_comments = 0; @@ -840,15 +842,25 @@ PlyFile *ply_read(FILE *fp, int *nelems, char ***elem_names) words = get_words (plyfile->fp, &nwords, &orig_line); if (!words || !equal_strings (words[0], "ply")) + { + if (words) free( words); + free( plyfile ); return (NULL); + } - while (words) { + while (words) + { /* parse words */ - if (equal_strings (words[0], "format")) { + if (equal_strings (words[0], "format")) + { if (nwords != 3) + { + free( words ); + free( plyfile ); return (NULL); + } if (equal_strings (words[1], "ascii")) plyfile->file_type = PLY_ASCII; else if (equal_strings (words[1], "binary_big_endian")) @@ -856,10 +868,11 @@ PlyFile *ply_read(FILE *fp, int *nelems, char ***elem_names) else if (equal_strings (words[1], "binary_little_endian")) plyfile->file_type = PLY_BINARY_LE; else - { - free (words); + { + free( words ); + free( plyfile ); return (NULL); - } + } plyfile->version = osg::asciiToDouble (words[2]); } else if (equal_strings (words[0], "element")) @@ -871,10 +884,10 @@ PlyFile *ply_read(FILE *fp, int *nelems, char ***elem_names) else if (equal_strings (words[0], "obj_info")) add_obj_info (plyfile, orig_line); else if (equal_strings (words[0], "end_header")) - { + { free (words); break; - } + } /* free up words space */ free (words); diff --git a/src/osgPlugins/pvr/ReaderWriterPVR.cpp b/src/osgPlugins/pvr/ReaderWriterPVR.cpp index 8a5a9a672..304825251 100644 --- a/src/osgPlugins/pvr/ReaderWriterPVR.cpp +++ b/src/osgPlugins/pvr/ReaderWriterPVR.cpp @@ -172,11 +172,18 @@ public: else hasAlpha = false; - osg::Image *image = new osg::Image; - unsigned char *imageData = new unsigned char[header.dataLength]; + osg::ref_ptr image = new osg::Image; + if (!image) return ReadResult::INSUFFICIENT_MEMORY_TO_LOAD; + + unsigned char *imageData = new unsigned char[header.dataLength]; + if (!imageData) return ReadResult::INSUFFICIENT_MEMORY_TO_LOAD; + fin.read((char*)imageData, header.dataLength); if(!fin.good()) + { + delete [] imageData; return ReadResult::ERROR_IN_READING_FILE; + } image->setImage(header.width, header.height, 1, internalFormat, internalFormat, @@ -227,7 +234,7 @@ public: if(!mipmapdata.empty()) image->setMipmapLevels(mipmapdata); - return image; + return image.get(); } osg::notify(osg::WARN) << "Failed to read pvr data." << std::endl; diff --git a/src/osgPlugins/shp/ESRIShapeParser.cpp b/src/osgPlugins/shp/ESRIShapeParser.cpp index 81a8ca8ea..c601036bf 100644 --- a/src/osgPlugins/shp/ESRIShapeParser.cpp +++ b/src/osgPlugins/shp/ESRIShapeParser.cpp @@ -25,6 +25,7 @@ ESRIShapeParser::ESRIShapeParser( const std::string fileName, bool useDouble ): if( (fd = open( fileName.c_str(), O_RDONLY )) <= 0 ) #endif { + if (fd) close ( fd ); perror( fileName.c_str() ); return ; } diff --git a/src/osgPlugins/shp/XBaseParser.cpp b/src/osgPlugins/shp/XBaseParser.cpp index f151b9e8c..f93d319c7 100644 --- a/src/osgPlugins/shp/XBaseParser.cpp +++ b/src/osgPlugins/shp/XBaseParser.cpp @@ -93,7 +93,8 @@ XBaseParser::XBaseParser(const std::string fileName): #endif { perror( fileName.c_str() ); - return ; + if (fd) close( fd ); + return; } } diff --git a/src/osgPlugins/zip/unzip.cpp b/src/osgPlugins/zip/unzip.cpp index 5b9ae05d5..dd5526851 100644 --- a/src/osgPlugins/zip/unzip.cpp +++ b/src/osgPlugins/zip/unzip.cpp @@ -3147,17 +3147,18 @@ unzFile unzOpenInternal(LUFILE *fin) // return UNZ_OK if there is no problem. int unzClose (unzFile file) { - unz_s* s; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; + + if (file==NULL) + return UNZ_PARAMERROR; + + unz_s* s=(unz_s*)file; if (s->pfile_in_zip_read!=NULL) unzCloseCurrentFile(file); - lufclose(s->file); - if (s) zfree(s); // unused s=0; - return UNZ_OK; + lufclose(s->file); + zfree(s); + return UNZ_OK; } @@ -4144,15 +4145,18 @@ ZRESULT TUnzip::Find(const TCHAR *tname,bool ic,int *index,ZIPENTRY *ze) void EnsureDirectory(const TCHAR *rootdir, const TCHAR *dir) { // first check that rootdir exists. nb. rootdir has a trailing slash if (rootdir!=0) - { TCHAR rd[MAX_PATH]; + { TCHAR rd[MAX_PATH+1]; #ifdef ZIP_STD strncpy(rd,rootdir,MAX_PATH); #else _tcsncpy_s(rd,MAX_PATH,rootdir,MAX_PATH); -#endif +#endif + + // make sure there rd is always null terminated + rd[MAX_PATH] = 0; - size_t len=_tcslen(rd); + size_t len=_tcslen(rd); if (len>0 && (rd[len-1]=='/' || rd[len-1]=='\\')) rd[len-1]=0; #ifdef ZIP_STD if (!FileExists(rd)) lumkdir(rd); diff --git a/src/osgShadow/MinimalCullBoundsShadowMap.cpp b/src/osgShadow/MinimalCullBoundsShadowMap.cpp index c00769bf3..b4bfc6bbd 100644 --- a/src/osgShadow/MinimalCullBoundsShadowMap.cpp +++ b/src/osgShadow/MinimalCullBoundsShadowMap.cpp @@ -328,7 +328,7 @@ osg::BoundingBox MinimalCullBoundsShadowMap::ViewData::ComputeRenderLeavesBounds // Don't trust already computed bounds for cull generated drawables // LightPointDrawable & LightPointSpriteDrawable are such examples // they store wrong recorded bounds from very first pass - if( rl && rl->_modelview == NULL ) + if(rl->_modelview == NULL ) rl->_drawable->dirtyBound(); bb = rl->_drawable->getBound(); diff --git a/src/osgViewer/ScreenCaptureHandler.cpp b/src/osgViewer/ScreenCaptureHandler.cpp index 89d2bd46d..93908b690 100644 --- a/src/osgViewer/ScreenCaptureHandler.cpp +++ b/src/osgViewer/ScreenCaptureHandler.cpp @@ -606,9 +606,10 @@ ScreenCaptureHandler::CaptureOperation* ScreenCaptureHandler::getCaptureOperatio void ScreenCaptureHandler::addCallbackToViewer(osgViewer::ViewerBase& viewer) { osg::Camera* camera = findAppropriateCameraForCallback(viewer); + if (!camera) return; WindowCaptureCallback* callback = static_cast(_callback.get()); - if (camera && callback->getFramePosition() == WindowCaptureCallback::START_FRAME) + if (callback && callback->getFramePosition() == WindowCaptureCallback::START_FRAME) { camera->setInitialDrawCallback(_callback.get()); } @@ -621,9 +622,10 @@ void ScreenCaptureHandler::addCallbackToViewer(osgViewer::ViewerBase& viewer) void ScreenCaptureHandler::removeCallbackFromViewer(osgViewer::ViewerBase& viewer) { osg::Camera* camera = findAppropriateCameraForCallback(viewer); + if (!camera) return; WindowCaptureCallback* callback = static_cast(_callback.get()); - if (camera && callback->getFramePosition() == WindowCaptureCallback::START_FRAME) + if (callback && callback->getFramePosition() == WindowCaptureCallback::START_FRAME) { camera->setInitialDrawCallback(0); } diff --git a/src/osgVolume/Locator.cpp b/src/osgVolume/Locator.cpp index 627050f25..fe51c9963 100644 --- a/src/osgVolume/Locator.cpp +++ b/src/osgVolume/Locator.cpp @@ -207,6 +207,7 @@ void Locator::removeCallback(LocatorCallback* callback) if (*itr == callback) { _locatorCallbacks.erase(itr); + return; } } } diff --git a/src/osgVolume/RayTracedTechnique.cpp b/src/osgVolume/RayTracedTechnique.cpp index 385996fc9..752c210c9 100644 --- a/src/osgVolume/RayTracedTechnique.cpp +++ b/src/osgVolume/RayTracedTechnique.cpp @@ -269,16 +269,6 @@ void RayTracedTechnique::init() osg::ref_ptr tf_texture = new osg::Texture1D; tf_texture->setImage(tf->getImage()); -#if 1 - osgDB::writeImageFile(*(tf->getImage()),"tf.png"); - OSG_NOTICE<<"imageLayer->getTexelOffset()[3]="<getTexelOffset()[3]<getTexelScale()[3]="<getTexelScale()[3]<getMinimum()="<getMinimum()<getMaximum()="<getMaximum()<setResizeNonPowerOfTwoHint(false); tf_texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); tf_texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); diff --git a/src/osgWrappers/serializers/osg/ShaderBinary.cpp b/src/osgWrappers/serializers/osg/ShaderBinary.cpp index f23a18536..484ed6294 100644 --- a/src/osgWrappers/serializers/osg/ShaderBinary.cpp +++ b/src/osgWrappers/serializers/osg/ShaderBinary.cpp @@ -25,7 +25,7 @@ static bool readData( osgDB::InputStream& is, osg::ShaderBinary& sb ) is >> osgDB::END_BRACKET; } sb.assign( size, (unsigned char*)data ); - delete data; + delete [] data; return true; }