Fix coverity finding: fix possible use after free..
parent
243df452a4
commit
a66e644bf3
|
@ -102,12 +102,16 @@ static const aiImporterDesc desc = {
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Constructor to be privately used by Importer
|
// Constructor to be privately used by Importer
|
||||||
XGLImporter::XGLImporter()
|
XGLImporter::XGLImporter()
|
||||||
{}
|
: m_reader( nullptr )
|
||||||
|
, m_scene( nullptr ) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Destructor, private as well
|
// Destructor, private as well
|
||||||
XGLImporter::~XGLImporter()
|
XGLImporter::~XGLImporter() {
|
||||||
{}
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Returns whether the class can handle the format of the given file.
|
// Returns whether the class can handle the format of the given file.
|
||||||
|
@ -149,7 +153,7 @@ void XGLImporter::InternReadFile( const std::string& pFile,
|
||||||
free_it free_it_really(dest);
|
free_it free_it_really(dest);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
scene = pScene;
|
m_scene = pScene;
|
||||||
std::shared_ptr<IOStream> stream( pIOHandler->Open( pFile, "rb"));
|
std::shared_ptr<IOStream> stream( pIOHandler->Open( pFile, "rb"));
|
||||||
|
|
||||||
// check whether we can read from the file
|
// check whether we can read from the file
|
||||||
|
@ -211,14 +215,13 @@ void XGLImporter::InternReadFile( const std::string& pFile,
|
||||||
|
|
||||||
// construct the irrXML parser
|
// construct the irrXML parser
|
||||||
CIrrXML_IOStreamReader st(stream.get());
|
CIrrXML_IOStreamReader st(stream.get());
|
||||||
std::unique_ptr<IrrXMLReader> read( createIrrXMLReader((IFileReadCallBack*) &st) );
|
m_reader.reset( createIrrXMLReader( ( IFileReadCallBack* ) &st ) );
|
||||||
reader = read.get();
|
|
||||||
|
|
||||||
// parse the XML file
|
// parse the XML file
|
||||||
TempScope scope;
|
TempScope scope;
|
||||||
|
|
||||||
while (ReadElement()) {
|
while (ReadElement()) {
|
||||||
if (!ASSIMP_stricmp(reader->getNodeName(),"world")) {
|
if (!ASSIMP_stricmp(m_reader->getNodeName(),"world")) {
|
||||||
ReadWorld(scope);
|
ReadWorld(scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,21 +234,21 @@ void XGLImporter::InternReadFile( const std::string& pFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy meshes
|
// copy meshes
|
||||||
scene->mNumMeshes = static_cast<unsigned int>(meshes.size());
|
m_scene->mNumMeshes = static_cast<unsigned int>(meshes.size());
|
||||||
scene->mMeshes = new aiMesh*[scene->mNumMeshes]();
|
m_scene->mMeshes = new aiMesh*[m_scene->mNumMeshes]();
|
||||||
std::copy(meshes.begin(),meshes.end(),scene->mMeshes);
|
std::copy(meshes.begin(),meshes.end(),m_scene->mMeshes);
|
||||||
|
|
||||||
// copy materials
|
// copy materials
|
||||||
scene->mNumMaterials = static_cast<unsigned int>(materials.size());
|
m_scene->mNumMaterials = static_cast<unsigned int>(materials.size());
|
||||||
scene->mMaterials = new aiMaterial*[scene->mNumMaterials]();
|
m_scene->mMaterials = new aiMaterial*[m_scene->mNumMaterials]();
|
||||||
std::copy(materials.begin(),materials.end(),scene->mMaterials);
|
std::copy(materials.begin(),materials.end(),m_scene->mMaterials);
|
||||||
|
|
||||||
if (scope.light) {
|
if (scope.light) {
|
||||||
scene->mNumLights = 1;
|
m_scene->mNumLights = 1;
|
||||||
scene->mLights = new aiLight*[1];
|
m_scene->mLights = new aiLight*[1];
|
||||||
scene->mLights[0] = scope.light;
|
m_scene->mLights[0] = scope.light;
|
||||||
|
|
||||||
scope.light->mName = scene->mRootNode->mName;
|
scope.light->mName = m_scene->mRootNode->mName;
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.dismiss();
|
scope.dismiss();
|
||||||
|
@ -254,8 +257,8 @@ void XGLImporter::InternReadFile( const std::string& pFile,
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
bool XGLImporter::ReadElement()
|
bool XGLImporter::ReadElement()
|
||||||
{
|
{
|
||||||
while(reader->read()) {
|
while(m_reader->read()) {
|
||||||
if (reader->getNodeType() == EXN_ELEMENT) {
|
if (m_reader->getNodeType() == EXN_ELEMENT) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -265,11 +268,11 @@ bool XGLImporter::ReadElement()
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
bool XGLImporter::ReadElementUpToClosing(const char* closetag)
|
bool XGLImporter::ReadElementUpToClosing(const char* closetag)
|
||||||
{
|
{
|
||||||
while(reader->read()) {
|
while(m_reader->read()) {
|
||||||
if (reader->getNodeType() == EXN_ELEMENT) {
|
if (m_reader->getNodeType() == EXN_ELEMENT) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (reader->getNodeType() == EXN_ELEMENT_END && !ASSIMP_stricmp(reader->getNodeName(),closetag)) {
|
else if (m_reader->getNodeType() == EXN_ELEMENT_END && !ASSIMP_stricmp(m_reader->getNodeName(),closetag)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,11 +283,11 @@ bool XGLImporter::ReadElementUpToClosing(const char* closetag)
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
bool XGLImporter::SkipToText()
|
bool XGLImporter::SkipToText()
|
||||||
{
|
{
|
||||||
while(reader->read()) {
|
while(m_reader->read()) {
|
||||||
if (reader->getNodeType() == EXN_TEXT) {
|
if (m_reader->getNodeType() == EXN_TEXT) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (reader->getNodeType() == EXN_ELEMENT || reader->getNodeType() == EXN_ELEMENT_END) {
|
else if (m_reader->getNodeType() == EXN_ELEMENT || m_reader->getNodeType() == EXN_ELEMENT_END) {
|
||||||
ThrowException("expected text contents but found another element (or element end)");
|
ThrowException("expected text contents but found another element (or element end)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -294,7 +297,7 @@ bool XGLImporter::SkipToText()
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
std::string XGLImporter::GetElementName()
|
std::string XGLImporter::GetElementName()
|
||||||
{
|
{
|
||||||
const char* s = reader->getNodeName();
|
const char* s = m_reader->getNodeName();
|
||||||
size_t len = strlen(s);
|
size_t len = strlen(s);
|
||||||
|
|
||||||
std::string ret;
|
std::string ret;
|
||||||
|
@ -328,7 +331,7 @@ void XGLImporter::ReadWorld(TempScope& scope)
|
||||||
nd->mName.Set("WORLD");
|
nd->mName.Set("WORLD");
|
||||||
}
|
}
|
||||||
|
|
||||||
scene->mRootNode = nd;
|
m_scene->mRootNode = nd;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -586,29 +589,29 @@ bool XGLImporter::ReadMesh(TempScope& scope)
|
||||||
ReadMaterial(scope);
|
ReadMaterial(scope);
|
||||||
}
|
}
|
||||||
else if (s == "p") {
|
else if (s == "p") {
|
||||||
if (!reader->getAttributeValue("ID")) {
|
if (!m_reader->getAttributeValue("ID")) {
|
||||||
LogWarn("no ID attribute on <p>, ignoring");
|
LogWarn("no ID attribute on <p>, ignoring");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int id = reader->getAttributeValueAsInt("ID");
|
int id = m_reader->getAttributeValueAsInt("ID");
|
||||||
t.points[id] = ReadVec3();
|
t.points[id] = ReadVec3();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (s == "n") {
|
else if (s == "n") {
|
||||||
if (!reader->getAttributeValue("ID")) {
|
if (!m_reader->getAttributeValue("ID")) {
|
||||||
LogWarn("no ID attribute on <n>, ignoring");
|
LogWarn("no ID attribute on <n>, ignoring");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int id = reader->getAttributeValueAsInt("ID");
|
int id = m_reader->getAttributeValueAsInt("ID");
|
||||||
t.normals[id] = ReadVec3();
|
t.normals[id] = ReadVec3();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (s == "tc") {
|
else if (s == "tc") {
|
||||||
if (!reader->getAttributeValue("ID")) {
|
if (!m_reader->getAttributeValue("ID")) {
|
||||||
LogWarn("no ID attribute on <tc>, ignoring");
|
LogWarn("no ID attribute on <tc>, ignoring");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int id = reader->getAttributeValueAsInt("ID");
|
int id = m_reader->getAttributeValueAsInt("ID");
|
||||||
t.uvs[id] = ReadVec2();
|
t.uvs[id] = ReadVec2();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -828,10 +831,10 @@ void XGLImporter::ReadFaceVertex(const TempMesh& t, TempFace& out)
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
unsigned int XGLImporter::ReadIDAttr()
|
unsigned int XGLImporter::ReadIDAttr()
|
||||||
{
|
{
|
||||||
for(int i = 0, e = reader->getAttributeCount(); i < e; ++i) {
|
for(int i = 0, e = m_reader->getAttributeCount(); i < e; ++i) {
|
||||||
|
|
||||||
if(!ASSIMP_stricmp(reader->getAttributeName(i),"id")) {
|
if(!ASSIMP_stricmp(m_reader->getAttributeName(i),"id")) {
|
||||||
return reader->getAttributeValueAsInt(i);
|
return m_reader->getAttributeValueAsInt(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ~0u;
|
return ~0u;
|
||||||
|
@ -844,7 +847,7 @@ float XGLImporter::ReadFloat()
|
||||||
LogError("unexpected EOF reading float element contents");
|
LogError("unexpected EOF reading float element contents");
|
||||||
return 0.f;
|
return 0.f;
|
||||||
}
|
}
|
||||||
const char* s = reader->getNodeData(), *se;
|
const char* s = m_reader->getNodeData(), *se;
|
||||||
|
|
||||||
if(!SkipSpaces(&s)) {
|
if(!SkipSpaces(&s)) {
|
||||||
LogError("unexpected EOL, failed to parse float");
|
LogError("unexpected EOL, failed to parse float");
|
||||||
|
@ -869,7 +872,7 @@ unsigned int XGLImporter::ReadIndexFromText()
|
||||||
LogError("unexpected EOF reading index element contents");
|
LogError("unexpected EOF reading index element contents");
|
||||||
return ~0u;
|
return ~0u;
|
||||||
}
|
}
|
||||||
const char* s = reader->getNodeData(), *se;
|
const char* s = m_reader->getNodeData(), *se;
|
||||||
if(!SkipSpaces(&s)) {
|
if(!SkipSpaces(&s)) {
|
||||||
LogError("unexpected EOL, failed to parse index element");
|
LogError("unexpected EOL, failed to parse index element");
|
||||||
return ~0u;
|
return ~0u;
|
||||||
|
@ -894,7 +897,7 @@ aiVector2D XGLImporter::ReadVec2()
|
||||||
LogError("unexpected EOF reading vec2 contents");
|
LogError("unexpected EOF reading vec2 contents");
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
const char* s = reader->getNodeData();
|
const char* s = m_reader->getNodeData();
|
||||||
|
|
||||||
for(int i = 0; i < 2; ++i) {
|
for(int i = 0; i < 2; ++i) {
|
||||||
if(!SkipSpaces(&s)) {
|
if(!SkipSpaces(&s)) {
|
||||||
|
@ -923,7 +926,7 @@ aiVector3D XGLImporter::ReadVec3()
|
||||||
LogError("unexpected EOF reading vec3 contents");
|
LogError("unexpected EOF reading vec3 contents");
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
const char* s = reader->getNodeData();
|
const char* s = m_reader->getNodeData();
|
||||||
|
|
||||||
for(int i = 0; i < 3; ++i) {
|
for(int i = 0; i < 3; ++i) {
|
||||||
if(!SkipSpaces(&s)) {
|
if(!SkipSpaces(&s)) {
|
||||||
|
|
|
@ -51,6 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <assimp/Importer.hpp>
|
#include <assimp/Importer.hpp>
|
||||||
#include <assimp/mesh.h>
|
#include <assimp/mesh.h>
|
||||||
#include <assimp/light.h>
|
#include <assimp/light.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
struct aiNode;
|
struct aiNode;
|
||||||
|
|
||||||
|
@ -203,12 +204,8 @@ private:
|
||||||
unsigned int ResolveMaterialRef(TempScope& scope);
|
unsigned int ResolveMaterialRef(TempScope& scope);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::shared_ptr<irr::io::IrrXMLReader> m_reader;
|
||||||
|
aiScene* m_scene;
|
||||||
private:
|
|
||||||
|
|
||||||
irr::io::IrrXMLReader* reader;
|
|
||||||
aiScene* scene;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace Assimp
|
} // end of namespace Assimp
|
||||||
|
|
Loading…
Reference in New Issue