OpenGEX: fix coverity findings.

pull/858/head
Kim Kulling 2016-05-14 10:10:05 +02:00
parent d6ecc8b621
commit 210182b17a
1 changed files with 71 additions and 68 deletions

View File

@ -133,7 +133,7 @@ namespace Grammar {
};
static int isValidMetricType( const char *token ) {
if( NULL == token ) {
if( nullptr == token ) {
return false;
}
@ -165,8 +165,7 @@ namespace Grammar {
return CameraNodeToken;
} else if ( LightNodeType == tokenType ) {
return LightNodeToken;
}
else if ( GeometryObjectType == tokenType ) {
} else if ( GeometryObjectType == tokenType ) {
return GeometryObjectToken;
} else if ( CameraObjectType == tokenType ) {
return CameraObjectToken;
@ -205,11 +204,11 @@ USE_ODDLPARSER_NS
//------------------------------------------------------------------------------------------------
static void propId2StdString( Property *prop, std::string &name, std::string &key ) {
name = key = "";
if ( NULL == prop ) {
if ( nullptr == prop ) {
return;
}
if ( NULL != prop->m_key ) {
if ( nullptr != prop->m_key ) {
name = prop->m_key->m_buffer;
if ( Value::ddl_string == prop->m_value->m_type ) {
key = prop->m_value->getString();
@ -220,9 +219,9 @@ static void propId2StdString( Property *prop, std::string &name, std::string &ke
//------------------------------------------------------------------------------------------------
OpenGEXImporter::VertexContainer::VertexContainer()
: m_numVerts( 0 )
, m_vertices(NULL)
, m_vertices( nullptr )
, m_numNormals( 0 )
, m_normals(NULL)
, m_normals( nullptr )
, m_numUVComps()
, m_textureCoords()
{
@ -254,17 +253,17 @@ OpenGEXImporter::RefInfo::~RefInfo() {
//------------------------------------------------------------------------------------------------
OpenGEXImporter::OpenGEXImporter()
: m_root( NULL )
: m_root( nullptr )
, m_nodeChildMap()
, m_meshCache()
, m_mesh2refMap()
, m_ctx( NULL )
, m_ctx( nullptr )
, m_metrics()
, m_currentNode( NULL )
, m_currentNode( nullptr )
, m_currentVertices()
, m_currentMesh( NULL )
, m_currentMaterial( NULL )
, m_currentLight( NULL )
, m_currentMesh( nullptr )
, m_currentMaterial( nullptr )
, m_currentLight( nullptr )
, m_currentCamera( nullptr )
, m_tokenType( Grammar::NoneType )
, m_materialCache()
@ -328,14 +327,14 @@ const aiImporterDesc *OpenGEXImporter::GetInfo() const {
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::SetupProperties( const Importer *pImp ) {
if( NULL == pImp ) {
if( nullptr == pImp ) {
return;
}
}
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleNodes( DDLNode *node, aiScene *pScene ) {
if( NULL == node ) {
if( nullptr == node ) {
return;
}
@ -426,7 +425,7 @@ void OpenGEXImporter::handleNodes( DDLNode *node, aiScene *pScene ) {
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleMetricNode( DDLNode *node, aiScene *pScene ) {
if( NULL == node || NULL == m_ctx ) {
if( nullptr == node || nullptr == m_ctx ) {
return;
}
@ -435,14 +434,14 @@ void OpenGEXImporter::handleMetricNode( DDLNode *node, aiScene *pScene ) {
}
Property *prop( node->getProperties() );
while( NULL != prop ) {
if( NULL != prop->m_key ) {
while( nullptr != prop ) {
if( nullptr != prop->m_key ) {
if( Value::ddl_string == prop->m_value->m_type ) {
std::string valName( ( char* ) prop->m_value->m_data );
int type( Grammar::isValidMetricType( valName.c_str() ) );
if( Grammar::NoneType != type ) {
Value *val( node->getValue() );
if( NULL != val ) {
if( nullptr != val ) {
if( Value::ddl_float == val->m_type ) {
m_metrics[ type ].m_floatValue = val->getFloat();
} else if( Value::ddl_int32 == val->m_type ) {
@ -489,10 +488,10 @@ static void getRefNames( DDLNode *node, std::vector<std::string> &names ) {
ai_assert( NULL != node );
Reference *ref = node->getReferences();
if( NULL != ref ) {
if( nullptr != ref ) {
for( size_t i = 0; i < ref->m_numRefs; i++ ) {
Name *currentName( ref->m_referencedName[ i ] );
if( NULL != currentName && NULL != currentName->m_id ) {
if( nullptr != currentName && nullptr != currentName->m_id ) {
const std::string name( currentName->m_id->m_buffer );
if( !name.empty() ) {
names.push_back( name );
@ -504,7 +503,7 @@ static void getRefNames( DDLNode *node, std::vector<std::string> &names ) {
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleObjectRefNode( DDLNode *node, aiScene *pScene ) {
if( NULL == m_currentNode ) {
if( nullptr == m_currentNode ) {
throw DeadlyImportError( "No parent node for name." );
return;
}
@ -524,7 +523,7 @@ void OpenGEXImporter::handleObjectRefNode( DDLNode *node, aiScene *pScene ) {
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleMaterialRefNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
if( NULL == m_currentNode ) {
if( nullptr == m_currentNode ) {
throw DeadlyImportError( "No parent node for name." );
return;
}
@ -603,7 +602,7 @@ void OpenGEXImporter::handleLightObject( ODDLParser::DDLNode *node, aiScene *pSc
Property *prop( node->findPropertyByName( "type" ) );
if ( nullptr != prop ) {
if ( NULL != prop->m_value ) {
if ( nullptr != prop->m_value ) {
std::string typeStr( prop->m_value->getString() );
if ( "point" == typeStr ) {
m_currentLight->mType = aiLightSource_POINT;
@ -621,14 +620,14 @@ void OpenGEXImporter::handleLightObject( ODDLParser::DDLNode *node, aiScene *pSc
//------------------------------------------------------------------------------------------------
static void setMatrix( aiNode *node, DataArrayList *transformData ) {
ai_assert( NULL != node );
ai_assert( NULL != transformData );
ai_assert( nullptr != node );
ai_assert( nullptr != transformData );
float m[ 16 ];
size_t i( 1 );
Value *next( transformData->m_dataList->m_next );
m[ 0 ] = transformData->m_dataList->getFloat();
while( next != NULL ) {
while( next != nullptr ) {
m[ i ] = next->getFloat();
next = next->m_next;
i++;
@ -657,13 +656,13 @@ static void setMatrix( aiNode *node, DataArrayList *transformData ) {
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleTransformNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
if( NULL == m_currentNode ) {
if( nullptr == m_currentNode ) {
throw DeadlyImportError( "No parent node for name." );
return;
}
DataArrayList *transformData( node->getDataArrayList() );
if( NULL != transformData ) {
if( nullptr != transformData ) {
if( transformData->m_numItems != 16 ) {
throw DeadlyImportError( "Invalid number of data for transform matrix." );
return;
@ -679,7 +678,7 @@ void OpenGEXImporter::handleMeshNode( ODDLParser::DDLNode *node, aiScene *pScene
m_meshCache.push_back( m_currentMesh );
Property *prop = node->getProperties();
if( NULL != prop ) {
if( nullptr != prop ) {
std::string propName, propKey;
propId2StdString( prop, propName, propKey );
if( "primitive" == propName ) {
@ -700,7 +699,7 @@ void OpenGEXImporter::handleMeshNode( ODDLParser::DDLNode *node, aiScene *pScene
handleNodes( node, pScene );
DDLNode *parent( node->getParent() );
if( NULL != parent ) {
if( nullptr != parent ) {
const std::string &name = parent->getName();
m_mesh2refMap[ name ] = meshidx;
}
@ -716,7 +715,7 @@ enum MeshAttribute {
//------------------------------------------------------------------------------------------------
static MeshAttribute getAttributeByName( const char *attribName ) {
ai_assert( NULL != attribName );
ai_assert( nullptr != attribName );
if( 0 == strncmp( "position", attribName, strlen( "position" ) ) ) {
return Position;
@ -731,8 +730,8 @@ static MeshAttribute getAttributeByName( const char *attribName ) {
//------------------------------------------------------------------------------------------------
static void fillVector3( aiVector3D *vec3, Value *vals ) {
ai_assert( NULL != vec3 );
ai_assert( NULL != vals );
ai_assert( nullptr != vec3 );
ai_assert( nullptr != vals );
float x( 0.0f ), y( 0.0f ), z( 0.0f );
Value *next( vals );
@ -740,7 +739,7 @@ static void fillVector3( aiVector3D *vec3, Value *vals ) {
next = next->m_next;
y = next->getFloat();
next = next->m_next;
if( NULL != next ) {
if( nullptr != next ) {
z = next->getFloat();
}
@ -750,13 +749,13 @@ static void fillVector3( aiVector3D *vec3, Value *vals ) {
//------------------------------------------------------------------------------------------------
static size_t countDataArrayListItems( DataArrayList *vaList ) {
size_t numItems( 0 );
if( NULL == vaList ) {
if( nullptr == vaList ) {
return numItems;
}
DataArrayList *next( vaList );
while( NULL != next ) {
if( NULL != vaList->m_dataList ) {
while( nullptr != next ) {
if( nullptr != vaList->m_dataList ) {
numItems++;
}
next = next->m_next;
@ -776,13 +775,13 @@ static void copyVectorArray( size_t numItems, DataArrayList *vaList, aiVector3D
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleVertexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
if( NULL == node ) {
if( nullptr == node ) {
throw DeadlyImportError( "No parent node for name." );
return;
}
Property *prop( node->getProperties() );
if( NULL != prop ) {
if( nullptr != prop ) {
std::string propName, propKey;
propId2StdString( prop, propName, propKey );
MeshAttribute attribType( getAttributeByName( propKey.c_str() ) );
@ -791,7 +790,7 @@ void OpenGEXImporter::handleVertexArrayNode( ODDLParser::DDLNode *node, aiScene
}
DataArrayList *vaList = node->getDataArrayList();
if( NULL == vaList ) {
if( nullptr == vaList ) {
return;
}
@ -815,18 +814,18 @@ void OpenGEXImporter::handleVertexArrayNode( ODDLParser::DDLNode *node, aiScene
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
if( NULL == node ) {
if( nullptr == node ) {
throw DeadlyImportError( "No parent node for name." );
return;
}
if( NULL == m_currentMesh ) {
if( nullptr == m_currentMesh ) {
throw DeadlyImportError( "No current mesh for index data found." );
return;
}
DataArrayList *vaList = node->getDataArrayList();
if( NULL == vaList ) {
if( nullptr == vaList ) {
return;
}
@ -877,7 +876,7 @@ void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *
//------------------------------------------------------------------------------------------------
static void getColorRGB( aiColor3D *pColor, DataArrayList *colList ) {
if( NULL == pColor || NULL == colList ) {
if( nullptr == pColor || nullptr == colList ) {
return;
}
@ -901,7 +900,7 @@ enum ColorType {
//------------------------------------------------------------------------------------------------
static ColorType getColorType( Text *id ) {
if ( NULL == id ) {
if ( nullptr == id ) {
return NoneColor;
}
@ -928,15 +927,15 @@ void OpenGEXImporter::handleMaterialNode( ODDLParser::DDLNode *node, aiScene *pS
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleColorNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
if( NULL == node ) {
if( nullptr == node ) {
return;
}
Property *prop = node->findPropertyByName( "attrib" );
if( NULL != prop ) {
if( NULL != prop->m_value ) {
if( nullptr != prop ) {
if( nullptr != prop->m_value ) {
DataArrayList *colList( node->getDataArrayList() );
if( NULL == colList ) {
if( nullptr == colList ) {
return;
}
aiColor3D col;
@ -957,15 +956,15 @@ void OpenGEXImporter::handleColorNode( ODDLParser::DDLNode *node, aiScene *pScen
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleTextureNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
if( NULL == node ) {
if( nullptr == node ) {
return;
}
Property *prop = node->findPropertyByName( "attrib" );
if( NULL != prop ) {
if( NULL != prop->m_value ) {
if( nullptr != prop ) {
if( nullptr != prop->m_value ) {
Value *val( node->getValue() );
if( NULL != val ) {
if( nullptr != val ) {
aiString tex;
tex.Set( val->getString() );
if( prop->m_value->getString() == Grammar::DiffuseTextureToken ) {
@ -992,24 +991,28 @@ void OpenGEXImporter::handleTextureNode( ODDLParser::DDLNode *node, aiScene *pSc
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleParamNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
if ( NULL == node ) {
if ( nullptr == node ) {
return;
}
Property *prop = node->findPropertyByName( "attrib" );
if ( nullptr != prop ) {
if ( NULL != prop->m_value ) {
Value *val( node->getValue() );
const float floatVal( val->getFloat() );
if ( NULL != val && prop->m_value != NULL ) {
if ( "fov" == prop->m_value->getString() ) {
m_currentCamera->mHorizontalFOV = floatVal;
} else if ( "near" == prop->m_value->getString() ) {
m_currentCamera->mClipPlaneNear = floatVal;
} else if ( "far" == prop->m_value->getString() ) {
m_currentCamera->mClipPlaneFar = floatVal;
}
if ( nullptr == prop ) {
return;
}
if ( nullptr != prop->m_value ) {
Value *val( node->getValue() );
if ( nullptr == val ) {
return;
}
const float floatVal( val->getFloat() );
if ( prop->m_value != nullptr ) {
if ( "fov" == prop->m_value->getString() ) {
m_currentCamera->mHorizontalFOV = floatVal;
} else if ( "near" == prop->m_value->getString() ) {
m_currentCamera->mClipPlaneNear = floatVal;
} else if ( "far" == prop->m_value->getString() ) {
m_currentCamera->mClipPlaneFar = floatVal;
}
}
}