# STLLoader: avoid potential division by zero.

# irrMeshLoader: fix potentially uninitialized variable.
Thanks to erikbuck for pointing these out (http://sourceforge.net/projects/assimp/forums/forum/817653/topic/4691387).

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1076 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/2/head
aramis_acg 2011-09-04 15:09:45 +00:00
parent c01d81c882
commit 4f1a95a584
2 changed files with 4 additions and 2 deletions

View File

@ -118,7 +118,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
// temporary data - current mesh buffer // temporary data - current mesh buffer
aiMaterial* curMat = NULL; aiMaterial* curMat = NULL;
aiMesh* curMesh = NULL; aiMesh* curMesh = NULL;
unsigned int curMatFlags; unsigned int curMatFlags = 0;
std::vector<aiVector3D> curVertices,curNormals,curTangents,curBitangents; std::vector<aiVector3D> curVertices,curNormals,curTangents,curBitangents;
std::vector<aiColor4D> curColors; std::vector<aiColor4D> curColors;

View File

@ -186,7 +186,7 @@ void STLImporter::LoadASCIIFile()
// try to guess how many vertices we could have // try to guess how many vertices we could have
// assume we'll need 160 bytes for each face // assume we'll need 160 bytes for each face
pMesh->mNumVertices = ( pMesh->mNumFaces = fileSize / 160 ) * 3; pMesh->mNumVertices = ( pMesh->mNumFaces = std::max(1u,fileSize / 160u )) * 3;
pMesh->mVertices = new aiVector3D[pMesh->mNumVertices]; pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
pMesh->mNormals = new aiVector3D[pMesh->mNumVertices]; pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
@ -207,6 +207,8 @@ void STLImporter::LoadASCIIFile()
DefaultLogger::get()->warn("STL: A new facet begins but the old is not yet complete"); DefaultLogger::get()->warn("STL: A new facet begins but the old is not yet complete");
} }
if (pMesh->mNumFaces == curFace) { if (pMesh->mNumFaces == curFace) {
ai_assert(pMesh->mNumFaces != 0);
// need to resize the arrays, our size estimate was wrong // need to resize the arrays, our size estimate was wrong
unsigned int iNeededSize = (unsigned int)(sz-mBuffer) / pMesh->mNumFaces; unsigned int iNeededSize = (unsigned int)(sz-mBuffer) / pMesh->mNumFaces;
if (iNeededSize <= 160)iNeededSize >>= 1; // prevent endless looping if (iNeededSize <= 160)iNeededSize >>= 1; // prevent endless looping